对于以 api 形式使用的 Dubbo 项目,需自己选择 Tracer 和 Exporter 依赖引入:
参考一,以 Opentelemetry 作为 Tracer,上报到 Zipkin
<!-- 必选,dubbo-tracing核心依赖 --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-tracing</artifactId> </dependency> <!-- Opentelemetry as Tracer --> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-tracing-bridge-otel</artifactId> </dependency> <!-- Zipkin as exporter --> <dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-exporter-zipkin</artifactId> </dependency>
参考二,以 Opentelemetry 作为 Tracer,上报到 OTlp
<!-- 必选,dubbo-tracing核心依赖 --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-tracing</artifactId> </dependency> <!-- Opentelemetry as Tracer --> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-tracing-bridge-otel</artifactId> </dependency> <!-- OTlp as exporter --> <dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-exporter-otlp</artifactId> </dependency>
public class TracingConfigProvider { public static TracingConfig getTracingConfig() { TracingConfig tracingConfig = new TracingConfig(); // 开启dubbo tracing tracingConfig.setEnabled(true); // 设置采样率 tracingConfig.setSampling(new SamplingConfig(1.0f)); // 设置Propagation,默认为W3C,可选W3C/B3 tracingConfig.setPropagation(new PropagationConfig("W3C")); // 设置trace上报 ExporterConfig exporterConfig = new ExporterConfig(); // 设置将trace上报到Zipkin exporterConfig.setZipkin(new ExporterConfig.ZipkinConfig("http://localhost:9411/api/v2/spans")); tracingConfig.setExporter(exporterConfig); return tracingConfig; } }