Class: OpenTelemetry::Context::Propagation::Propagator

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/context/propagation/propagator.rb

Overview

A propagator composes an extractor and injector into a single interface exposing inject and extract methods

Instance Method Summary collapse

Constructor Details

#initialize(injector, extractor) ⇒ Propagator

Returns a Propagator that delegates inject and extract to the provided injector and extractor

Parameters:



18
19
20
21
# File 'lib/opentelemetry/context/propagation/propagator.rb', line 18

def initialize(injector, extractor)
  @injector = injector
  @extractor = extractor
end

Instance Method Details

#extract(carrier, context = Context.current, &getter) ⇒ Context

Extracts and returns context from a carrier. Returns the provided context and logs a warning if an error if extraction fails.

Parameters:

  • carrier (Object)

    The carrier to extract context from

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

    Context to be updated with the state extracted from the carrier. Defaults to Context.current

  • 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 []=.

Returns:

  • (Context)

    a new context updated with state extracted from the carrier



55
56
57
58
59
60
# File 'lib/opentelemetry/context/propagation/propagator.rb', line 55

def extract(carrier, context = Context.current, &getter)
  @extractor.extract(carrier, context, &getter)
rescue => e # rubocop:disable Style/RescueStandardError
  OpenTelemetry.logger.warn "Error in Propagator#extract #{e.message}"
  context
end

#inject(carrier, context = Context.current, &setter) ⇒ Object

Returns a carrier with the provided context injected according the underlying injector. Returns the carrier and logs a warning if injection fails.

Parameters:

  • carrier (Object)

    A carrier to inject context into context into

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

    Context to be injected into carrier. Defaults to Context.current

  • setter (optional Callable)

    An optional callable that takes a carrier, a key and a value and assigns the key-value pair in the carrier. If omitted the default setter will be used which expects the carrier to respond to [] and []=.

Returns:

  • (Object)

    carrier



36
37
38
39
40
41
# File 'lib/opentelemetry/context/propagation/propagator.rb', line 36

def inject(carrier, context = Context.current, &setter)
  @injector.inject(carrier, context, &setter)
rescue => e # rubocop:disable Style/RescueStandardError
  OpenTelemetry.logger.warn "Error in Propagator#inject #{e.message}"
  carrier
end