This topic describes how to use SOFATracer with Zipkin to upload and display data.
If you have a simple Spring Web project built on SOFABoot, follow these steps:
Import dependencies
Add the SOFATracer dependency
Add the SOFATracer dependency to your project:
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-sofa-boot-starter</artifactId>
</dependency>Configure the Zipkin dependency
SOFATracer does not enable data uploads to Zipkin by default. To use this feature, add the following Zipkin reporting dependency:
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>2.11.12</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<version>2.7.13</version>
</dependency>Configuration file
In the application.properties file of your project, add the parameters that SOFATracer requires, such as spring.application.name and logging.path.
spring.application.name specifies the name of the current application.
logging.path specifies the output folder for logs.
# Application Name
spring.application.name=SOFATracerReportZipkin
# logging path
logging.path=./logs
com.alipay.sofa.tracer.zipkin.enabled=true
com.alipay.sofa.tracer.zipkin.baseUrl=http://localhost:9411Start the Zipkin server
Start the Zipkin server to accept and display traces reported by SOFATracer. For setup instructions, see the official Zipkin documentation.
Start the application
Import the project into your Integrated Development Environment (IDE) and start the application using the generated main method. Alternatively, you can run mvn spring-boot:run in the project's root directory. The startup log is displayed in the console:
2018-05-1213:12:05.868 INFO 76572---[ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:Mapping filter:'SpringMvcSofaTracerFilter' to urls:[/*]
2018-05-12 13:12:06.543 INFO 76572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/helloZipkin]}" onto public java.util.Map<java.lang.String, java.lang.Object> com.alipay.sofa.tracer.examples.zipkin.controller.SampleRestController.helloZipkin(java.lang.String)
2018-05-12 13:12:07.164 INFO 76572 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)Access the REST service by entering http://localhost:8080/helloZipkin in a browser. The following result is returned:
{
content:"Hello, SOFATracer Zipkin Remote Report!",
id:1,
success:true
}View the Zipkin server display
Open the Zipkin server interface. If the Zipkin server is deployed at http://localhost:9411, open the URL in your browser and search for helloZipkin. You can then view the corresponding event chain diagram.
Run a Spring project
For a typical Spring project, you can start the application using a servlet container, such as Tomcat or Jetty. For a project example, see Use SOFATracer in a Spring project.