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 creates a new span, wrapping the method call or reactive type.

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

  • The @SpanTag annotation can be used on method arguments to include the value of the argument within a Span’s tags. When you use @SpanTag on an 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 starts a new span
2Use @SpanTag to include method arguments as tags for the span
3Use the @ContinueSpan annotation to continue an 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.