diff --git a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb index 3a66675dd..59c5efeb5 100644 --- a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb +++ b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb @@ -9,9 +9,6 @@ module OpenTelemetry module Processor module Baggage - class BaggageSpanProcessor - # Called when a {Span} is started, if the {Span#recording?} returns true. - # # The BaggageSpanProcessor reads key/values stored in Baggage in the # starting span's parent context and adds them as attributes to the span. # @@ -29,7 +26,7 @@ class BaggageSpanProcessor # @example # OpenTelemetry::SDK.configure do |c| # # Add the BaggageSpanProcessor to the collection of span processors - # c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new) + # c.add_span_processor(Honeycomb::OpenTelemetry::Trace::BaggageSpanProcessor.new) # # # Because the span processor list is no longer empty, the SDK will not use the # # values in OTEL_TRACES_EXPORTER to instantiate exporters. @@ -43,36 +40,40 @@ class BaggageSpanProcessor # ) # ) # end - # - # @param [Span] span the {Span} that just started, expected to conform - # to the concrete {Span} interface from the SDK and respond to :add_attributes. - # @param [Context] parent_context the parent {Context} of the newly - # started span. - def on_start(span, parent_context) + class BaggageSpanProcessor + # Called when a {Span} is started, adds Baggage keys/values to the span as attributes. + # + # @param [Span] span the {Span} that just started, expected to conform + # to the concrete {Span} interface from the SDK and respond to :add_attributes. + # @param [Context] parent_context the parent {Context} of the newly + # started span. + 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)) - end + end - # NO-OP method to satisfy the SpanProcessor duck type. - # - # @param [Span] span the {Span} that just ended. - def on_finish(span); end + # NO-OP method to satisfy the SpanProcessor duck type. + # + # @param [Span] span the {Span} that just ended. + def on_finish(span); end - # Export all ended spans to the configured `Exporter` that have not yet - # been exported. - # - # @param [optional Numeric] timeout An optional timeout in seconds. - # @return [Integer] 0 for success and there is nothing to flush so always successful. - def force_flush(timeout: nil) + # Export all ended spans to the configured `Exporter` that have not yet + # been exported. + # + # @param [optional Numeric] timeout An optional timeout in seconds. + # @return [Integer] 0 for success and there is nothing to flush so always successful. + def force_flush(timeout: nil) 0 - end + end - # Called when {TracerProvider#shutdown} is called. - # - # @param [optional Numeric] timeout An optional timeout in seconds. - # @return [Integer] 0 for success and there is nothing to stop so always successful. - def shutdown(timeout: nil) + # Called when {TracerProvider#shutdown} is called. + # + # @param [optional Numeric] timeout An optional timeout in seconds. + # @return [Integer] 0 for success and there is nothing to stop so always successful. + def shutdown(timeout: nil) 0 + end end end end