Class: OpenTelemetry::Propagator::B3::Single::TextMapPropagator

Inherits:
Object
  • Object
show all
Includes:
TextMapExtractor
Defined in:
lib/opentelemetry/propagator/b3/single/text_map_propagator.rb

Overview

Propagates trace context using the b3 single header format

Instance Method Summary collapse

Methods included from TextMapExtractor

#extract

Instance Method Details

#fieldsArray<String>

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

Returns:

  • (Array<String>)

    a list of fields that will be used by this propagator.



57
58
59
# 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) ⇒ Object

Inject trace context into the supplied carrier.

Parameters:

  • carrier (Carrier)

    The mutable carrier to inject trace context into

  • context (Context) (defaults to: Context.current)

    The context to read trace context from

  • setter (optional Setter) (defaults to: Context::Propagation.text_map_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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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