Class: OpenTelemetry::Baggage::Propagation::TextMapInjector

Inherits:
Object
  • Object
show all
Includes:
Context::Propagation::DefaultSetter
Defined in:
lib/opentelemetry/baggage/propagation/text_map_injector.rb

Overview

Injects baggage using the W3C Baggage format

Instance Method Summary collapse

Methods included from Context::Propagation::DefaultSetter

#default_setter

Constructor Details

#initialize(baggage_key: 'baggage') ⇒ TextMapInjector

Returns a new TextMapInjector that injects context using the specified header key

Parameters:

  • baggage_key (String) (defaults to: 'baggage')

    The baggage header key used in the carrier



22
23
24
# File 'lib/opentelemetry/baggage/propagation/text_map_injector.rb', line 22

def initialize(baggage_key: 'baggage')
  @baggage_key = baggage_key
end

Instance Method Details

#inject(carrier, context) {|Carrier, String| ... } ⇒ Object

Inject in-process baggage into the supplied carrier.

Parameters:

  • carrier (Carrier)

    The carrier to inject baggage into

  • context (Context)

    The context to read baggage from

  • getter (optional Callable)

    An optional callable that takes a carrier and a key and returns the value associated with the key. If omitted the default getter will be used which expects the carrier to respond to [] and []=.

Yields:

  • (Carrier, String)

    if an optional getter is provided, inject will yield the carrier and the header key to the getter.

Returns:

  • (Object)

    carrier with injected baggage



36
37
38
39
40
41
42
43
# File 'lib/opentelemetry/baggage/propagation/text_map_injector.rb', line 36

def inject(carrier, context, &setter)
  return carrier unless (baggage = context[ContextKeys.baggage_key]) && !baggage.empty?

  setter ||= default_setter
  setter.call(carrier, @baggage_key, encode(baggage))

  carrier
end