Class ClientTracingFilter

java.lang.Object
io.helidon.tracing.jersey.client.ClientTracingFilter
All Implemented Interfaces:
ClientRequestFilter, ClientResponseFilter

@Priority(750) public class ClientTracingFilter extends Object implements ClientRequestFilter, ClientResponseFilter
This filter adds tracing information the the associated JAX-RS client call based on the provided properties.

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:

  1. From request property TRACER_PROPERTY_NAME
  2. From JAX-RS server, when the client is invoked in scope of a JAX-RS inbound request and appropriate filter is configured (see helidon-tracing-jersey and helidon-microprofile-tracing modules)
  3. From Tracer.global()

The parent SpanContext is resolved as follows

  1. From request property CURRENT_SPAN_CONTEXT_PROPERTY_NAME
  2. From JAX-RS server, when the client is invoked in scope of a JAX-rs inbound request

Inbound HTTP headers are resolved from JAX-RS server.

For each client call, a new Span with operation name generated from HTTP method and resource method and class 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();
 
  • Field Details

    • JAX_RS_TRACING_COMPONENT

      public static final String JAX_RS_TRACING_COMPONENT
      Name of tracing component used to retrieve tracing configuration.
      See Also:
    • TRACER_PROPERTY_NAME

      public static final String TRACER_PROPERTY_NAME
      The Tracer property name.
      See Also:
    • SPAN_NAME_PROPERTY_NAME

      public static final String SPAN_NAME_PROPERTY_NAME
      Override name of the span created for client call.
    • ENABLED_PROPERTY_NAME

      public static final String ENABLED_PROPERTY_NAME
      If set to false, tracing will be disabled. If set to true, tracing will depend on overall configuration.
    • CURRENT_SPAN_CONTEXT_PROPERTY_NAME

      public static final String CURRENT_SPAN_CONTEXT_PROPERTY_NAME
      The SpanContext property name.
      See Also:
    • X_OT_SPAN_CONTEXT

      public static final String X_OT_SPAN_CONTEXT
      Header used by Envoy proxy. Automatically propagated when within Jersey and when using helidon-microprofile-tracing module.
      See Also:
    • X_REQUEST_ID

      public static final String X_REQUEST_ID
      Header used by routers. Automatically propagated when within Jersey and when using helidon-microprofile-tracing module.
      See Also:
  • Constructor Details

    • ClientTracingFilter

      public ClientTracingFilter()
      Default constructor so this filter can be registered with Jersey as a class. Required by integrated platform.
  • Method Details