弹簧 - 千分尺 + opentelemetry-exporter-otlp

Key*_*rys 4 spring spring-boot micrometer

是否可以配置千分尺在春季将跟踪信息发送到otel容器?

我轻松配置了向 Zipkin 和 Wavefront 发送跨度: https://docs.spring.io/spring-boot/docs/3.1.0-SNAPSHOT/reference/htmlsingle/#actuator.micrometer-tracing.tracers但没有关于导出的内容到酒店。

Micrometer 文档也没有提到将跨度导出到 otel 容器https://micrometer.io/docs/tracing#_using_micrometer_tracing_directly

spring boot 3 需要在 pom.xml 中包含哪些依赖项才能成功运行

jim*_*b_o 10

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.trace.export.SpanExporter;

/**
 * As of SpringBoot 3.0.2 the inclusion of io.micrometer:micrometer-tracing-bridge-otel and
 * io.opentelemetry:opentelemetry-exporter-otlp is not sufficient to bootstrap the SpanExporter. Adding
 * io.opentelemetry:opentelemetry-sdk-extension-autoconfigure also does not help. Hence this solution which will
 * probably be redundant one day.
 */
@Configuration
public class OpenTelemetryConfig {

    @Value("${otel.exporter.otlp.traces.endpoint:http://localhost:4317}")
    private String tracesEndpoint;

    @Bean
    public SpanExporter spanExporter() {
        return OtlpGrpcSpanExporter.builder().setEndpoint(tracesEndpoint).build();
    }

}
Run Code Online (Sandbox Code Playgroud)

如果您想使用 io.opentelemetry.instrumentation:opentelemetry-jdbc (可能还有其他),我还发现以下内容是必要的,因为它依赖于 GlobalOpenTelemetry.get()。这迫使它成为微米追踪桥酒店产生的实例。

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;

@Configuration
public class GlobalOpenTelemetrySetter implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if (bean instanceof OpenTelemetry openTelemetry) {
            GlobalOpenTelemetry.set(openTelemetry);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

}
Run Code Online (Sandbox Code Playgroud)

我担心这可能会有启动竞争条件,但目前对我有用。我希望 Spring 团队能够在某个时候提供适当的澄清。