Class TracedResource
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.
- Author:
- Adam Lindenthal
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappLevelLogging(ContainerRequestContext context) Resource method with explicit logging into resource span.childSpan(ContainerRequestContext context) Resource method with explicit child span creation.Resource method with no explicit tracing.failTrace(ContainerRequestContext context) tracePost(String entity, ContainerRequestContext context) Similar asappLevelLogging(ContainerRequestContext), just withPOSTmethod.voidtraceWithAsync(AsyncResponse asyncResponse, ContainerRequestContext context) traceWithManagedClient(ContainerRequestContext context, WebTarget wt) Resource method with explicit span creation and propagation into injected managed client.
-
Constructor Details
-
TracedResource
public TracedResource()
-
-
Method Details
-
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 Response appLevelLogging(@Context ContainerRequestContext context) throws InterruptedException Resource 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 Response tracePost(String entity, @Context ContainerRequestContext context) Similar asappLevelLogging(ContainerRequestContext), just withPOSTmethod.- Parameters:
entity- posted entitycontext- injected context- Returns:
- dummy response
-
childSpan
@GET @Path("childSpan") public Response childSpan(@Context ContainerRequestContext context) throws InterruptedException Resource 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 Response traceWithManagedClient(@Context ContainerRequestContext context, @Uri("resource/appLevelPost") 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 AsyncResponse asyncResponse, @Context ContainerRequestContext context) -
failTrace
-