Class TraceContexts

java.lang.Object
org.apache.juneau.rest.server.tracing.TraceContexts

public final class TraceContexts extends Object
Neutral, dependency-free helper for stamping a caller's current trace context into an arbitrary TraceContextCarrier.

juneau-rest-server has no first-party call site for this helper — it exists so a future MCP-client (or any other non-HTTP caller) adapter can inject the active trace context into whatever carrier it builds (for example a RequestMeta being sent as a JSON-RPC request's params._meta) without that adapter depending on OpenTelemetry. The adapter depends only on this class and the installed TracerHook.

Off-by-default contract

inject(TracerHook, TraceContextCarrier) does nothing but null-check its arguments and delegate to TracerHook.inject(TraceContextCarrier). Against NoOpTracerHook (or any bridge that does not override inject), the default no-op implementation writes nothing to the carrier — only a bridge with an actual trace context to render (for example the OpenTelemetry bridge in juneau-rest-server-tracing-otel) writes traceparent / tracestate / baggage keys.

See Also:
Since:
10.0.0
  • Method Details

    • inject

      public static void inject(TracerHook tracer, TraceContextCarrier carrier)
      Injects the caller's current trace context (as understood by tracer) into carrier.
      Parameters:
      tracer - The TracerHook whose active trace context (if any) should be rendered. Must not be null.
      carrier - The TraceContextCarrier to write into. Must not be null.