Distributed tracing (Spring Cloud SOFA Tracer)

Updated at:

Spring Cloud SOFA integrates SOFATracer, an open source distributed tracing system from Ant Group. SOFATracer follows the OpenTracing specification and uses a global TraceId to trace a single request across multiple service nodes. The trace data can be reported to a server for display, providing visibility into network calls.

Spring Cloud SOFA Tracer integrates seamlessly with RMS, the SOFA real-time monitoring system. After you add Spring Cloud SOFA Tracer to your project and deploy the RMS agent, you can use RMS to view the complete service trace and the time spent in each phase. This data is useful for troubleshooting and performance analysis. You can also configure the system to report trace information to RMS or the open source tool Zipkin.

For more information about SOFATracer, see What is SOFATracer?.

Configure distributed tracing

  1. Add the Spring Cloud SOFA Tracer dependency to your project.

    Do not configure the version. The version is controlled by dependencyManagement. This demo uses SpringMVC to publish a REST service and OpenFeign and RestTemplate to call it. The related dependencies are included.

    <dependency>
         <groupId>com.alipay.cloud</groupId>
         <artifactId>spring-cloud-starter-sofa-tracer</artifactId>
    </dependency>
    <!-- Import service framework -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <!-- Import load balancer -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
  2. Start the test application and trigger a service invocation.

    After the service invocation is complete, view the trace logs in the {user.dir}/logs/tracelog directory. In this example, the following files are generated:

    feign-digest.log
    feign-stat.log
    resttemplate-digest.log
    resttemplate-stat.log
    spring-mvc-digest.log
    spring-mvc-stat.log
    static-info.log
    tracer-self.log

    For descriptions of these files and their formats, see Log description.