tree: faef85fc11b0670fbbf11388a5dc69654e7e6798 [path history] [tgz]
  1. dubbo-samples-spring-boot3-tracing-consumer/
  2. dubbo-samples-spring-boot3-tracing-interface/
  3. dubbo-samples-spring-boot3-tracing-provider/
  4. static/
  5. pom.xml
  6. README.md
4-governance/dubbo-samples-spring-boot3-tracing/README.md

Overview

This example demonstrates the basic usage of tracing in Dubbo application and report tracing information to zipkin. This example contains three parts, dubbo-samples-spring-boot3-tracing-provider , dubbo-samples-spring-boot3-tracing-consumer and dubbo-samples-spring-boot3-tracing-interface.

Apache Dubbo has inbuilt tracing through Micrometer Observations and Micrometer Tracing.

Quick Start

Install & Start Zipkin

Follow Zipkin's quick start to install zipkin.

Here we use docker to quickly start a zipkin server.

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

Then you can verify zipkin server works by access http://localhost:9411

zipkin_home

Install & Start Nacos

Follow Nacos's quick start to install and start nacos.

Start Provider

Start org.apache.dubbo.springboot.demo.provider.ProviderApplication directly from IDE.

Start Consumer

Start org.apache.dubbo.springboot.demo.consumer.ConsumerApplication directly from IDE.

Check Result

Open http://localhost:9411/zipkin/ in browser.

zipkin.png

How To Use Dubbo Tracing In Your Project

1. Adding dubbo-spring-boot-observability-starter To Your Project

For the Springboot project, you can use dubbo-spring-boot-observability-starter to easily have observability, Dubbo provides two types of starters at present, select one to add to pom:


<!-- Opentelemetry as Tracer, Zipkin as exporter --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-tracing-otel-zipkin-spring-boot-starter</artifactId> </dependency>

<!-- Brave as Tracer, Zipkin as exporter --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-tracing-brave-zipkin-spring-boot-starter</artifactId> </dependency>

Please note that this Dubbo upgrade has changed the dependency name, which is quite tricky. We recommend visiting the Dubbo version release page to obtain the latest source code updates. For reference, visit https://cn.dubbo.apache.org/en/download/.

Dubbo will support more in the future, such as skywalking, Jagger.

2. Configuration Tracing

application.yml:

my-address: 127.0.0.1

spring:
  application:
    name: dubbo-springboot3-tracing-provider/consumer
dubbo:
  application:
    name: ${spring.application.name}
  protocol:
    name: dubbo
    port: -1
  registry:
    id: nacos-registry
    address: nacos://${my-address}:8848
  config-center:
    address: nacos://${my-address}:8848
  metadata-report:
    address: nacos://${my-address}:8848
  tracing:
    enabled: true # default is false
    sampling:
      probability: 0.5 # sampling rate, default is 0.1
    propagation:
      type: W3C # W3C/B3 default is W3C
    tracing-exporter:
      zipkin-config:
        endpoint: http://${my-address}:9411/api/v2/spans
        connect-timeout: 1s # connect timeout, default is 1s
        read-timeout: 10s # read timeout, default is 10s

logging:
  level:
    root: info
  pattern:
    console: '[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2} [%X{traceId:-}, %X{spanId:-}]: %m%n'

Among these steps, we need to manually configure “my-address” to the addresses where we run Nacos and Zipkin.

3. Customizing Observation Filters

To customize the tags present in metrics (low cardinality tags) and in spans (low and high cardinality tags) you should create your own versions of DubboServerObservationConvention (server side) and DubboClientObservationConvention ( client side) and register them in the ApplicationModel's BeanFactory. To reuse the existing ones check DefaultDubboServerObservationConvention (server side) and DefaultDubboClientObservationConvention (client side).

Extension

An OpenZipkin URL sender dependency to send out spans to Zipkin via a URLConnectionSender

<dependency>
    <groupId>io.zipkin.reporter2</groupId>
    <artifactId>zipkin-sender-urlconnection</artifactId>
    <version>3.3.0</version>
</dependency>

or use following code to solve it:

<dependency>
    <groupId>io.zipkin.reporter2</groupId>
    <artifactId>zipkin-reporter</artifactId>
    <version>3.3.0</version>
</dependency>
<dependency>
    <groupId>io.zipkin.reporter2</groupId>
    <artifactId>zipkin-sender-okhttp3</artifactId>
    <version>3.3.0</version>
</dependency>