Tracing Annotations

The io.micronaut.tracing.annotation package contains annotations that can be declared on methods to create new spans or continue existing spans.

The available annotations are:

  • The @NewSpan annotation will create a new span, wrapping the method call or reactive type.

  • The @ContinueSpan annotation will continue an existing span, wrapping the method call or reactive type.

  • The @SpanTag annotation can be used on method arguments to include the value of each argument within a Span’s tags. When you use @SpanTag on a method argument, you need either to annotate the method with @NewSpan or @ContinueSpan.

The following snippet presents an example of using the annotations:

Using Trace Annotations

  1. @Singleton
  2. class HelloService {
  3. @NewSpan("hello-world") (1)
  4. public String hello(@SpanTag("person.name") String name) { (2)
  5. return greet("Hello " + name);
  6. }
  7. @ContinueSpan (3)
  8. public String greet(@SpanTag("hello.greeting") String greet) {
  9. return greet;
  10. }
  11. }
1The @NewSpan annotation is used to start a new span
2You can use @SpanTag to include arguments of methods as tags for the span
3The @ContinueSpan annotation can be used to continue as existing span and incorporate additional tags using @SpanTag

Tracing Instrumentation

In addition to explicit tracing tags, Micronaut includes a number of instrumentations to ensure that the Span context is propagated between threads and across Microservice boundaries.

These instrumentations are found in the io.micronaut.tracing.instrument package and include HTTP Client Filters and Server Filters to propagate the necessary headers via HTTP.