class OpenTelemetry::Propagator::B3::Single::TextMapPropagator

Propagates trace context using the b3 single header format

Constants

FIELDS

Public Instance Methods

fields() click to toggle source

Returns the predefined propagation fields. If your carrier is reused, you should delete the fields returned by this method before calling inject.

@return [Array<String>] a list of fields that will be used by this propagator.

# File lib/opentelemetry/propagator/b3/single/text_map_propagator.rb, line 57
def fields
  FIELDS
end
inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) click to toggle source

Inject trace context into the supplied carrier.

@param [Carrier] carrier The mutable carrier to inject trace context into @param [Context] context The context to read trace context from @param [optional Setter] setter If the optional setter is provided, it

will be used to write context into the carrier, otherwise the default
text map setter will be used.
# File lib/opentelemetry/propagator/b3/single/text_map_propagator.rb, line 35
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
  span_context = Trace.current_span(context).context
  return unless span_context.valid?

  sampling_state = if B3.debug?(context)
                     'd'
                   elsif span_context.trace_flags.sampled?
                     '1'
                   else
                     '0'
                   end

  b3_value = "#{span_context.hex_trace_id}-#{span_context.hex_span_id}-#{sampling_state}"

  setter.set(carrier, B3_CONTEXT_KEY, b3_value)
  nil
end