Class TracedResource
- java.lang.Object
-
- org.glassfish.jersey.examples.opentracing.TracedResource
-
@Path("/resource") public class TracedResource extends ObjectOpenTracing example resource.Jersey (with registered
OpenTracingFeaturewill automatically create and start span for each request ("root" span or "request" span) and a child span to be used in the resource method ("resource" span). The root span is used for Jersey-level event logging (resource matching started, request filters applied, etc). The resource span serves for application-level event logging purposes (used-defined). Both are automatically created and also automatically finished.Resource span is created right before the resource method invocation and finished right after resource method finishes. It can be resolved by calling
OpenTracingUtils.getRequestSpan(ContainerRequestContext).Application code can also create ad-hoc spans as child spans of the resource span. This can be achieved by calling one of the convenience methods
OpenTracingUtils.getRequestChildSpan(ContainerRequestContext).ContainerRequestContextcan be obtained via injection.All the ad-hoc created spans MUST be
finishedexplicitly.- Author:
- Adam Lindenthal
-
-
Constructor Summary
Constructors Constructor Description TracedResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.ws.rs.core.ResponseappLevelLogging(jakarta.ws.rs.container.ContainerRequestContext context)Resource method with explicit logging into resource span.jakarta.ws.rs.core.ResponsechildSpan(jakarta.ws.rs.container.ContainerRequestContext context)Resource method with explicit child span creation.jakarta.ws.rs.core.ResponsedefaultTrace()Resource method with no explicit tracing.StringfailTrace(jakarta.ws.rs.container.ContainerRequestContext context)jakarta.ws.rs.core.ResponsetracePost(String entity, jakarta.ws.rs.container.ContainerRequestContext context)Similar asappLevelLogging(ContainerRequestContext), just withPOSTmethod.voidtraceWithAsync(jakarta.ws.rs.container.AsyncResponse asyncResponse, jakarta.ws.rs.container.ContainerRequestContext context)jakarta.ws.rs.core.ResponsetraceWithManagedClient(jakarta.ws.rs.container.ContainerRequestContext context, jakarta.ws.rs.client.WebTarget wt)Resource method with explicit span creation and propagation into injected managed client.
-
-
-
Method Detail
-
defaultTrace
@GET @Path("defaultTrace") public jakarta.ws.rs.core.Response defaultTrace()Resource method with no explicit tracing.One span (jersey-server) will be created and finished automatically.
- Returns:
- dummy response
-
appLevelLogging
@GET @Path("appLevelLogging") public jakarta.ws.rs.core.Response appLevelLogging(@Context jakarta.ws.rs.container.ContainerRequestContext context) throws InterruptedExceptionResource method with explicit logging into resource span.- Parameters:
context- injected request context with resource-level span reference- Returns:
- dummy response
- Throws:
InterruptedException- if interrupted
-
tracePost
@POST @Path("appLevelPost") public jakarta.ws.rs.core.Response tracePost(String entity, @Context jakarta.ws.rs.container.ContainerRequestContext context)Similar asappLevelLogging(ContainerRequestContext), just withPOSTmethod.- Parameters:
entity- posted entitycontext- injected context- Returns:
- dummy response
-
childSpan
@GET @Path("childSpan") public jakarta.ws.rs.core.Response childSpan(@Context jakarta.ws.rs.container.ContainerRequestContext context) throws InterruptedExceptionResource method with explicit child span creation.- Parameters:
context- injected request context with resource-level (parent) span reference- Returns:
- dummy response
- Throws:
InterruptedException- if interrupted
-
traceWithManagedClient
@GET @Path("managedClient") public jakarta.ws.rs.core.Response traceWithManagedClient(@Context jakarta.ws.rs.container.ContainerRequestContext context, @Uri("resource/appLevelPost") jakarta.ws.rs.client.WebTarget wt)Resource method with explicit span creation and propagation into injected managed client.Shows how to propagate the server-side span into managed client (or any common Jersey client). This way, the client span will be child of the resource span.
- Parameters:
context- injected contextwt- injected web target- Returns:
- dummy response
-
traceWithAsync
@GET @Path("async") @ManagedAsync public void traceWithAsync(@Suspended jakarta.ws.rs.container.AsyncResponse asyncResponse, @Context jakarta.ws.rs.container.ContainerRequestContext context)
-
failTrace
@GET @Path("error") public String failTrace(@Context jakarta.ws.rs.container.ContainerRequestContext context)
-
-