Class W3CPropagation

java.lang.Object
brave.propagation.Propagation.Factory
io.micrometer.tracing.brave.bridge.W3CPropagation
All Implemented Interfaces:
brave.propagation.Propagation<String>

public class W3CPropagation extends brave.propagation.Propagation.Factory implements brave.propagation.Propagation<String>
Adopted from OpenTelemetry API.

Implementation of the TraceContext propagation protocol. See w3c/distributed-tracing.

Since:
1.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface brave.propagation.Propagation

    brave.propagation.Propagation.Factory, brave.propagation.Propagation.Getter<R,K>, brave.propagation.Propagation.KeyFactory<K>, brave.propagation.Propagation.RemoteGetter<R>, brave.propagation.Propagation.RemoteSetter<R>, brave.propagation.Propagation.Setter<R,K>
  • Field Summary

    Fields inherited from interface brave.propagation.Propagation

    B3_SINGLE_STRING, B3_STRING
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of W3CPropagation without baggage support.
    W3CPropagation(io.micrometer.tracing.BaggageManager baggageManager, List<String> localFields)
    Creates an instance of W3CPropagation with baggage support.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R> brave.propagation.TraceContext.Extractor<R>
    extractor(brave.propagation.Propagation.Getter<R,String> getter)
    This does not set the shared flag when extracting headers
    brave.propagation.Propagation<String>
    get()
     
    <R> brave.propagation.TraceContext.Injector<R>
    injector(brave.propagation.Propagation.Setter<R,String> setter)
     
     

    Methods inherited from class brave.propagation.Propagation.Factory

    create, decorate, requires128BitTraceId, supportsJoin

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • W3CPropagation

      public W3CPropagation(io.micrometer.tracing.BaggageManager baggageManager, List<String> localFields)
      Creates an instance of W3CPropagation with baggage support.
      Parameters:
      baggageManager - baggage manager
      localFields - local fields to be registered as baggage
    • W3CPropagation

      public W3CPropagation()
      Creates an instance of W3CPropagation without baggage support.
  • Method Details

    • get

      public brave.propagation.Propagation<String> get()
      Overrides:
      get in class brave.propagation.Propagation.Factory
    • keys

      public List<String> keys()
      Specified by:
      keys in interface brave.propagation.Propagation<String>
    • injector

      public <R> brave.propagation.TraceContext.Injector<R> injector(brave.propagation.Propagation.Setter<R,String> setter)
      Specified by:
      injector in interface brave.propagation.Propagation<String>
    • extractor

      public <R> brave.propagation.TraceContext.Extractor<R> extractor(brave.propagation.Propagation.Getter<R,String> getter)
      This does not set the shared flag when extracting headers

      TraceContext.shared() is not set here because it is not a remote propagation field. shared is a field in the Zipkin JSON v2 format only set after header extraction, for Span.Kind.SERVER spans implicitly via Tracer.joinSpan(TraceContext).

      Blindly setting shared regardless of this is harmful when Tracer.currentSpan() or similar are used, as any data tagged with these could also set the shared flag when reporting. Particularly, this can cause problems for multi- Span.Kind.CONSUMER spans. Regardless, setting invalid flags add overhead.

      In summary, while shared is propagated in-process, it has never been propagated out of process, and so should never be set when extracting headers. Hence, this code will not set TraceContext.shared().

      Specified by:
      extractor in interface brave.propagation.Propagation<String>