Zipkin

This example demonstrates a basic example of Dubbo integrating Zipkin for end-to-end tracing.

This example demonstrates a basic example of Dubbo integrating Zipkin for end-to-end tracing. For the complete code, please refer to dubbo-samples-tracing-zipkin, which consists of three parts:

  • dubbo-samples-spring-boot3-tracing-provider
  • dubbo-samples-spring-boot3-tracing-consumer
  • dubbo-samples-spring-boot3-tracing-interface

Quick Start

Install & Launch Zipkin

Refer to Zipkin’s quick start to install Zipkin.

Here we use Docker to demonstrate how to quickly start the Zipkin service.

  1. docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin

Next, you can confirm that Zipkin is working properly through the following link: [http://localhost:9411](http://localhost:9411)

zipkin_home

Install & Launch Nacos

Follow Nacos’s quick start to quickly install and launch Nacos.

Start Example Provider

Run org.apache.dubbo.springboot.demo.provider.ProviderApplication directly in the IDE.

Start Example Consumer

Run org.apache.dubbo.springboot.demo.consumer.ConsumerApplication directly in the IDE.

Check Monitoring Effects

Open http://localhost:9411/zipkin/ in your browser to see the effects.

zipkin.png

How to Use Dubbo Tracing in SpringBoot Projects

Choose one from the two starters below to add to your project, with differences in the choice of Tracer, one is Opentelemetry, and the other is Brave:

  1. <!-- Opentelemetry as Tracer, Zipkin as exporter -->
  2. <dependency>
  3. <groupId>org.apache.dubbo</groupId>
  4. <artifactId>dubbo-spring-boot-tracing-otel-zipkin-starter</artifactId>
  5. </dependency>
  1. <!-- Brave as Tracer, Zipkin as exporter -->
  2. <dependency>
  3. <groupId>org.apache.dubbo</groupId>
  4. <artifactId>dubbo-spring-boot-tracing-brave-zipkin-starter</artifactId>
  5. </dependency>

2. Configuration

Add the following configuration in application.yml:

  1. dubbo:
  2. tracing:
  3. enabled: true # Default is false
  4. sampling:
  5. probability: 0.5 # Sampling rate, default is 0.1
  6. propagation:
  7. type: W3C # Propagator type: W3C/B3, default is W3C
  8. tracing-exporter:
  9. zipkin-config:
  10. endpoint: http://localhost:9411/api/v2/spans
  11. connect-timeout: 1s # Connection timeout, default is 1s
  12. read-timeout: 10s # Data transmission timeout, default is 10s
  13. # Output tracing information to logging
  14. logging:
  15. pattern:
  16. level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]'

Extension

Choose the Right Sender

The Sender in Zipkin is a client implementation for the Exporter to report the traced data, all implementations can be referenced here.

There are many implementations of Sender:

  • URLConnectionSender reports via Java’s built-in HTTP client
  • OkHttpSender reports via OKHttp3
  • KafkaSender reports via Kafka messaging queue
  • ActiveMQSender reports via ActiveMQ messaging queue
  • RabbitMQSender reports via RabbitMQ messaging queue

Currently, the default starter for Dubbo Tracing uses OKHttpSender and also supports URLConnectionSender. If you want to send Spans to Zipkin via URLConnectionSender, you can directly add the following dependency in your pom:

  1. <dependency>
  2. <groupId>io.zipkin.reporter2</groupId>
  3. <artifactId>zipkin-sender-urlconnection</artifactId>
  4. </dependency>

Configure Zipkin’s endpoint, connectTimeout, readTimeout.

  1. dubbo:
  2. tracing:
  3. enabled: true # Default is false
  4. tracing-exporter:
  5. zipkin-config:
  6. endpoint: http://localhost:9411/api/v2/spans
  7. connect-timeout: 1s # Connection timeout, default is 1s
  8. read-timeout: 10s # Data transmission timeout, default is 10s

If you want to use other types of Sender, you will need to manually inject the corresponding Bean in your project and configure the corresponding properties, such as KafkaSender:

  1. @Configuration
  2. public class KafkaSenderConfiguration {
  3. @Bean
  4. KafkaSender kafkaSender(){
  5. KafkaSender.Builder builder = KafkaSender.newBuilder();
  6. builder.bootstrapServers("127.0.0.0.1:9092");
  7. builder.topic("zipkin");
  8. builder.encoding(Encoding.JSON);
  9. return builder.build();
  10. }
  11. }

SpringBoot2 Example

The usage of dubbo-tracing remains largely the same between SpringBoot2 and 3, the example for SpringBoot2 can be referenced at code address.

Non-SpringBoot Project Example

For non-SpringBoot projects, tracing can also be used through the Dubbo Bootstrap API method, detailed examples can be referenced at code address

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)