Class OpenTracingUtils

java.lang.Object
org.glassfish.jersey.opentracing.OpenTracingUtils

public class OpenTracingUtils extends Object
Utility methods for Jersey OpenTracing integration.
Since:
2.26
Author:
Adam Lindenthal
  • Method Details

    • getRequestSpan

      public static Optional<io.opentracing.Span> getRequestSpan(ContainerRequestContext context)
      Resolve resource-level span.

      If open tracing is enabled and GlobalTracer is registered, resource-level span should be stored in the OpenTracingFeature.SPAN_CONTEXT_PROPERTY. This span is resolved and returned as an Optional.

      Parameters:
      context - ContainerRequestContext instance, can be obtained via @Context injection
      Returns:
      Optional of the resolved span, if found; empty optional if not
    • getRequestChildSpan

      public static io.opentracing.Span getRequestChildSpan(ContainerRequestContext context)
      Create and start ad-hoc custom span with the default name as a child span of the request span (if available).
      Parameters:
      context - ContainerRequestContext instance, can be obtained via @Context injection
      Returns:
      If parent span ("request span") instance is stored in the ContainerRequestContext, new span is created as a child span of the found span. If no parent span found, new "root" span is created. In both cases, the returned span is already started. In order to successfully store the tracing, Span.finish() needs to be invoked explicitly, after the traced code finishes.
    • getRequestChildSpan

      public static io.opentracing.Span getRequestChildSpan(ContainerRequestContext context, String spanName)
      Create and start ad-hoc custom span with a custom name as a child span of the request span (if available).
      Parameters:
      context - ContainerRequestContext instance, can be obtained via @Context injection
      spanName - name to be used for the created span
      Returns:
      If parent span ("request span") instance is stored in the ContainerRequestContext, new span is created as a child span of the found span. If no parent span found, new "root" span is created. In both cases, the returned span is already started. In order to successfully store the tracing, Span.finish() needs to be invoked explicitly, after the traced code finishes.