Class: OpenTelemetry::Trace::Propagation::TraceContext::ResponseTextMapPropagator

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator.rb

Overview

Propagates trace response using the W3C Trace Context format w3c.github.io/trace-context/#traceresponse-header

Instance Method Summary collapse

Instance Method Details

#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context

Extract trace context from the supplied carrier. This is a no-op for this propagator, and will return the provided context.

Parameters:

  • carrier (Carrier)

    The carrier to get the header from

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

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

  • getter (optional Getter) (defaults to: Context::Propagation.text_map_getter)

    If the optional getter is provided, it will be used to read the header from the carrier, otherwise the default text map getter will be used.

Returns:

  • (Context)

    the original context.



46
47
48
# File 'lib/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator.rb', line 46

def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
  context
end

#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.



54
55
56
# File 'lib/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator.rb', line 54

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.



27
28
29
30
31
32
33
# File 'lib/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator.rb', line 27

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, TRACERESPONSE_KEY, TraceParent.from_span_context(span_context).to_s)
  nil
end