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
@Singleton
class HelloService {
@NewSpan("hello-world") (1)
public String hello(@SpanTag("person.name") String name) { (2)
return greet("Hello " + name);
}
@ContinueSpan (3)
public String greet(@SpanTag("hello.greeting") String greet) {
return greet;
}
}
1 | The @NewSpan annotation starts a new span |
2 | Use @SpanTag to include method arguments as tags for the span |
3 | Use 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.