Class: OpenTelemetry::CorrelationContext::Propagation::TextInjector

Inherits:
Object
  • Object
show all
Includes:
OpenTelemetry::Context::Propagation::DefaultSetter
Defined in:
lib/opentelemetry/correlation_context/propagation/text_injector.rb

Overview

Injects correlation context using the W3C Correlation Context format

Instance Method Summary collapse

Methods included from OpenTelemetry::Context::Propagation::DefaultSetter

#default_setter

Constructor Details

#initialize(correlation_context_key: 'Correlation-Context') ⇒ TextInjector

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

Parameters:

  • correlation_context_header_key (String)

    The correlation context header key used in the carrier



22
23
24
# File 'lib/opentelemetry/correlation_context/propagation/text_injector.rb', line 22

def initialize(correlation_context_key: 'Correlation-Context')
  @correlation_context_key = correlation_context_key
end

Instance Method Details

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

Inject in-process correlations into the supplied carrier.

Parameters:

  • carrier (Carrier)

    The carrier to inject correlations into

  • context (Context)

    The context to read correlations 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 correlations



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

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

  setter ||= default_setter
  setter.call(carrier, @correlation_context_key, encode(correlations))

  carrier
end