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
@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 is used to start a new span |
2 | You can use @SpanTag to include arguments of methods as tags for the span |
3 | The @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.