O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tracer injection

The application can inject an io.opentracing.Tracer bean that exposes the full OpenTracing API. This allows application developers to leverage more advanced use cases, such as adding metadata to the currently active span, manually creating spans, using baggage for context propagation, or initializing additional third-party instrumentation.

The following code shows how the tracer is used to attach data to the currently active span, (1):

@Path("/")public class Service {    @Inject    private Tracer tracer;    @GET    @Path("")    @Produces(MediaType.TEXT_PLAIN)    public String greeting() {       tracer.activeSpan()           .setTag("greeting", "hello"); (1)       return "hello";   }}

This can be useful for adding business-related data to spans, but also to log ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required