@Path(value="/resource") public class TracedResource extends Object
Jersey (with registered OpenTracingFeature will 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).
ContainerRequestContext can be obtained via injection.
All the ad-hoc created spans MUST be finished explicitly.
| Constructor and Description |
|---|
TracedResource() |
| Modifier and Type | Method and Description |
|---|---|
javax.ws.rs.core.Response |
appLevelLogging(javax.ws.rs.container.ContainerRequestContext context)
Resource method with explicit logging into resource span.
|
javax.ws.rs.core.Response |
childSpan(javax.ws.rs.container.ContainerRequestContext context)
Resource method with explicit child span creation.
|
javax.ws.rs.core.Response |
defaultTrace()
Resource method with no explicit tracing.
|
String |
failTrace(javax.ws.rs.container.ContainerRequestContext context) |
javax.ws.rs.core.Response |
tracePost(String entity,
javax.ws.rs.container.ContainerRequestContext context)
Similar as
appLevelLogging(ContainerRequestContext), just with POST method. |
void |
traceWithAsync(javax.ws.rs.container.AsyncResponse asyncResponse,
javax.ws.rs.container.ContainerRequestContext context) |
javax.ws.rs.core.Response |
traceWithManagedClient(javax.ws.rs.container.ContainerRequestContext context,
javax.ws.rs.client.WebTarget wt)
Resource method with explicit span creation and propagation into injected managed client.
|
@GET @Path(value="defaultTrace") public javax.ws.rs.core.Response defaultTrace()
One span (jersey-server) will be created and finished automatically.
@GET
@Path(value="appLevelLogging")
public javax.ws.rs.core.Response appLevelLogging(@Context
javax.ws.rs.container.ContainerRequestContext context)
throws InterruptedException
context - injected request context with resource-level span referenceInterruptedException - if interrupted@POST @Path(value="appLevelPost") public javax.ws.rs.core.Response tracePost(String entity, @Context javax.ws.rs.container.ContainerRequestContext context)
appLevelLogging(ContainerRequestContext), just with POST method.entity - posted entitycontext - injected context@GET
@Path(value="childSpan")
public javax.ws.rs.core.Response childSpan(@Context
javax.ws.rs.container.ContainerRequestContext context)
throws InterruptedException
context - injected request context with resource-level (parent) span referenceInterruptedException - if interrupted@GET
@Path(value="managedClient")
public javax.ws.rs.core.Response traceWithManagedClient(@Context
javax.ws.rs.container.ContainerRequestContext context,
@Uri(value="resource/appLevelPost")
javax.ws.rs.client.WebTarget wt)
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.
context - injected contextwt - injected web target@GET
@Path(value="async")
@ManagedAsync
public void traceWithAsync(@Suspended
javax.ws.rs.container.AsyncResponse asyncResponse,
@Context
javax.ws.rs.container.ContainerRequestContext context)
@GET @Path(value="error") public String failTrace(@Context javax.ws.rs.container.ContainerRequestContext context)
Copyright © 2007-2021, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.