Class: OpenTelemetry::Processor::Baggage::BaggageSpanProcessor
- Inherits:
-
SDK::Trace::SpanProcessor
- Object
- SDK::Trace::SpanProcessor
- OpenTelemetry::Processor::Baggage::BaggageSpanProcessor
- Defined in:
- lib/opentelemetry/processor/baggage/baggage_span_processor.rb
Overview
The BaggageSpanProcessor reads key/values stored in Baggage in the starting span's parent context and adds them as attributes to the span, if a key matches a provided predicate lambda.
Keys and values added to Baggage will appear on all subsequent child spans, not the current active span, for a trace within this service and will be propagated to external services via propagation headers.
If the external services also have a Baggage span processor, the keys and values will appear in those child spans as well.
⚠️ To repeat: a consequence of adding data to Baggage is that the keys and values will appear in all outgoing HTTP headers from the application. Do not put sensitive information in Baggage. ⚠️
Instance Method Summary collapse
-
#force_flush(timeout: nil) ⇒ Integer
Always successful; this processor does not maintain any state to flush.
-
#initialize(baggage_key_predicate) ⇒ BaggageSpanProcessor
constructor
Create a new BaggageSpanProcessor that reads Baggage keys and values from the parent context and adds them as attributes to the span.
-
#on_finish(span) ⇒ Object
Called when a Span is ended, does nothing.
-
#on_start(span, parent_context) ⇒ Object
Called when a
Span
is started, adds Baggage keys/values to the span as attributes. -
#shutdown(timeout: nil) ⇒ Integer
Always successful; this processor does not maintain any state to clean up or processes to close on shutdown.
Constructor Details
#initialize(baggage_key_predicate) ⇒ BaggageSpanProcessor
Create a new BaggageSpanProcessor that reads Baggage keys and values from the parent context and adds them as attributes to the span.
74 75 76 77 78 79 |
# File 'lib/opentelemetry/processor/baggage/baggage_span_processor.rb', line 74 def initialize(baggage_key_predicate) raise ArgumentError, 'baggage_key_predicate must respond to :call (lambda/Proc)' unless baggage_key_predicate.respond_to?(:call) @baggage_key_predicate = baggage_key_predicate super() end |
Instance Method Details
#force_flush(timeout: nil) ⇒ Integer
Always successful; this processor does not maintain any state to flush.
NO-OP method to satisfy the SpanProcessor
duck type.
110 111 112 |
# File 'lib/opentelemetry/processor/baggage/baggage_span_processor.rb', line 110 def force_flush(timeout: nil) 0 end |
#on_finish(span) ⇒ Object
Called when a Span is ended, does nothing.
NO-OP method to satisfy the SpanProcessor duck type.
102 |
# File 'lib/opentelemetry/processor/baggage/baggage_span_processor.rb', line 102 def on_finish(span); end |
#on_start(span, parent_context) ⇒ Object
Called when a Span
is started, adds Baggage keys/values to the span as attributes.
87 88 89 90 91 92 93 94 95 |
# File 'lib/opentelemetry/processor/baggage/baggage_span_processor.rb', line 87 def on_start(span, parent_context) return unless span.respond_to?(:add_attributes) && parent_context.is_a?(::OpenTelemetry::Context) span.add_attributes( ::OpenTelemetry::Baggage .values(context: parent_context) .select { |k, _v| @baggage_key_predicate.call(k) } ) end |
#shutdown(timeout: nil) ⇒ Integer
Always successful; this processor does not maintain any state to clean up or processes to close on shutdown.
NO-OP method to satisfy the SpanProcessor
duck type.
120 121 122 |
# File 'lib/opentelemetry/processor/baggage/baggage_span_processor.rb', line 120 def shutdown(timeout: nil) 0 end |