public class ClientTracingFilter extends Object implements ClientRequestFilter, ClientResponseFilter
In order to inject the tracing information properly, Tracer and an optional parent
SpanContext needs to be resolved. In case we are in scope of inbound JAX-RS
request, the client also uses inbound HTTP headers to determine correct headers for outbound call.
The Tracer gets resolved in the following order:
TRACER_PROPERTY_NAMEGlobalTracer.get()
The parent SpanContext is resolved as follows
CURRENT_SPAN_CONTEXT_PROPERTY_NAMEInbound HTTP headers are resolved from JAX-RS server.
For each client call, a new Span with operation name "jersey-client-call" is created based
on the resolved Tracer and an optional parent Span. The span information is also
propagated to the outbound request using HTTP headers injected by tracer.
Example 1 - client within a JAX-RS resource (with tracing integration configured on server):
public String someMethod(@Uri(BACKEND) WebTarget target) {
Response response = target.request().get();
// process the response
}
Example 2 - standalone client (with access to tracer and span),
assuming we have a WebTarget ready as target
target.request() .property(TracingClientFilter.TRACER_PROPERTY_NAME, tracer) .property(TracingClientFilter.CURRENT_SPAN_CONTEXT_PROPERTY_NAME, spanContext) .get();
| Modifier and Type | Field and Description |
|---|---|
static String |
CURRENT_SPAN_CONTEXT_PROPERTY_NAME
The
SpanContext property name. |
static String |
SPAN_OPERATION_NAME
Operation name of a span created for outbound calls.
|
static String |
TRACER_PROPERTY_NAME
The
Tracer property name. |
static String |
X_OT_SPAN_CONTEXT
Header used by Envoy proxy.
|
static String |
X_REQUEST_ID
Header used by routers.
|
| Constructor and Description |
|---|
ClientTracingFilter()
Default constructor so this filter can be registered with Jersey
as a class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
filter(ClientRequestContext requestContext) |
void |
filter(ClientRequestContext requestContext,
ClientResponseContext responseContext) |
public static final String TRACER_PROPERTY_NAME
Tracer property name.public static final String CURRENT_SPAN_CONTEXT_PROPERTY_NAME
SpanContext property name.public static final String SPAN_OPERATION_NAME
public static final String X_OT_SPAN_CONTEXT
public static final String X_REQUEST_ID
public ClientTracingFilter()
public void filter(ClientRequestContext requestContext)
filter in interface ClientRequestFilterpublic void filter(ClientRequestContext requestContext, ClientResponseContext responseContext)
filter in interface ClientResponseFilterCopyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.