Class: OpenTelemetry::Propagator::B3::Multi::TextMapPropagator

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

Overview

Propagates trace context using the B3 multi 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/multi/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/multi/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?

  setter.set(carrier, B3_TRACE_ID_KEY, span_context.hex_trace_id)
  setter.set(carrier, B3_SPAN_ID_KEY, span_context.hex_span_id)

  if B3.debug?(context)
    setter.set(carrier, B3_FLAGS_KEY, '1')
  elsif span_context.trace_flags.sampled?
    setter.set(carrier, B3_SAMPLED_KEY, '1')
  else
    setter.set(carrier, B3_SAMPLED_KEY, '0')
  end

  nil
end