Customized tracing with Zipkin is supported to allow users to add tracing spans at points of interest.
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>tracing-zipkin</artifactId>
</dependency>
@EnableZipkinTracing on your application entry or configurationImport tracing.zipkin.EnableZipkinTracing package
import org.apache.servicecomb.tracing.zipkin.EnableZipkinTracing;
Add annotation @EnableZipkinTracing
@SpringBootApplication
@EnableZipkinTracing
public class ZipkinSpanTestApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinSpanTestApplication.class);
}
}
@SpanImport tracing.Span package
import org.apache.servicecomb.tracing.Span;
Add annotation @Span
@Component
public class SlowRepoImpl implements SlowRepo {
private static final Logger logger = LoggerFactory.getLogger(SlowRepoImpl.class);
private final Random random = new Random();
@Span
@Override
public String crawl() throws InterruptedException {
logger.info("in /crawl");
Thread.sleep(random.nextInt(200));
return "crawled";
}
}
That's it!
Customized tracing span includes two pieces of data:
e.g. the example SlowRepoImpl in the previous section reports the following span
| key | value |
|---|---|
| span name | crawl |
| call.path | public abstract java.lang.String org.apache.servicecomb.tests.tracing.SlowRepo.crawl() throws java.lang.InterruptedException |
@Span must be a spring managed bean. If you want to do load-time weaving for non spring beans, you have to do it manually according to this answer.