@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 |
|---|---|
Response |
appLevelLogging(ContainerRequestContext context)
Resource method with explicit logging into resource span.
|
Response |
childSpan(ContainerRequestContext context)
Resource method with explicit child span creation.
|
Response |
defaultTrace()
Resource method with no explicit tracing.
|
String |
failTrace(ContainerRequestContext context) |
Response |
tracePost(String entity,
ContainerRequestContext context)
Similar as
appLevelLogging(ContainerRequestContext), just with POST method. |
void |
traceWithAsync(AsyncResponse asyncResponse,
ContainerRequestContext context) |
Response |
traceWithManagedClient(ContainerRequestContext context,
WebTarget wt)
Resource method with explicit span creation and propagation into injected managed client.
|
@GET @Path(value="defaultTrace") public Response defaultTrace()
One span (jersey-server) will be created and finished automatically.
@GET @Path(value="appLevelLogging") public Response appLevelLogging(@Context ContainerRequestContext context) throws InterruptedException
context - injected request context with resource-level span referenceInterruptedException - if interrupted@POST @Path(value="appLevelPost") public Response tracePost(String entity, @Context ContainerRequestContext context)
appLevelLogging(ContainerRequestContext), just with POST method.entity - posted entitycontext - injected context@GET @Path(value="childSpan") public Response childSpan(@Context ContainerRequestContext context) throws InterruptedException
context - injected request context with resource-level (parent) span referenceInterruptedException - if interrupted@GET @Path(value="managedClient") public Response traceWithManagedClient(@Context ContainerRequestContext context, @Uri(value="resource/appLevelPost") 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 AsyncResponse asyncResponse, @Context ContainerRequestContext context)
Copyright © 2007-2023, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.