Configuring Tracing with Helidon MP

Tracing support is implemented for both for Helidon MP Server and for Jersey client.

Declare the following dependency in your project:

<dependency>
    <groupId>io.helidon.microprofile.tracing</groupId>
    <artifactId>helidon-microprofile-tracing</artifactId>
</dependency>
Copied

In addition you need to add one of the tracer implementations (Zipkin or Jaeger).

The minimal required configuration is tracing.service that contains the service name to be associated with tracing spans sent by this instance.

All tracer specific configuration is expected in config under tracing.

Example microprofile-config.properties with minimal tracer configuration:

tracing.service=helidon-mp

For additional supported properties, please see tracing configuration

Creating custom spans

MicroProfile OpenTracing implementation will add support to simply add custom spans by annotation. Until we implement this support, you can configure custom spans as follows (in JAX-RS resources):

@Context
io.helidon.webserver.ServerRequest serverRequest;

//...

Span span = GlobalTracer.get()
        .buildSpan("my-operation")
        .asChildOf(serverRequest.spanContext())
        .start();
Copied

Trace propagation across services

Automated trace propagation is supported currently only with Jersey client.

Tracing propagation works automatically as long as you execute the client call in the same thread as the Jersey server side.

Exceptions that require manual handling:

  • When the resource method is annotated with Fault Tolerance annotations (e.g. @Fallback)

  • When you use async() on the Jersey client request

In such cases, you must provide the SpanContext by hand:

Tracing propagation with Jersey client (on a different thread)
import static io.helidon.tracing.jersey.client.ClientTracingFilter.CURRENT_SPAN_CONTEXT_PROPERTY_NAME;
import static io.helidon.tracing.jersey.client.ClientTracingFilter.TRACER_PROPERTY_NAME;

// ...

Response response = client.target(serviceEndpoint)
    .request()
    // tracer should be provided unless available as GlobalTracer
    .property(TRACER_PROPERTY_NAME, tracer)
    .property(CURRENT_SPAN_CONTEXT_PROPERTY_NAME, spanContext)
    .get();
Copied

Tracer and SpanContext can be obtained from ServerRequest that can be injected into Resource classes:

@Context
io.helidon.webserver.ServerRequest serverRequest;

//...

SpanContext spanContext = serverRequest.spanContext();
// optional, you could also use GlobalTracer.get() if it is configured
Tracer tracer = req.webServer().configuration().tracer();