diff --git a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb index 2b8b45f79..1f7bfc779 100644 --- a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb +++ b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb @@ -25,32 +25,24 @@ describe OpenTelemetry::Processor::Baggage::BaggageSpanProcessor do let(:processor) { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new } - let(:exporter) { TEST_EXPORTER } - - before do - exporter.reset - end + let(:span) { Minitest::Mock.new } + let(:context_with_baggage) { OpenTelemetry::Baggage.set_value('a_key', 'a_value') } describe '#on_start' do - before do - @span = Minitest::Mock.new - @context_with_baggage = OpenTelemetry::Baggage.set_value('a_key', 'a_value') - end - it 'adds current baggage keys/values as attributes when a span starts' do - @span.expect(:add_attributes, @span, [{ 'a_key' => 'a_value' }]) + span.expect(:add_attributes, span, [{ 'a_key' => 'a_value' }]) - processor.on_start(@span, @context_with_baggage) + processor.on_start(span, context_with_baggage) - @span.verify + span.verify end it 'does not blow up when given nil context' do - processor.on_start(@span, nil) + processor.on_start(span, nil) assert true # nothing above raised an exception end it 'does not blow up when given nil span' do - processor.on_start(nil, @context_with_baggage) + processor.on_start(nil, context_with_baggage) assert true # nothing above raised an exception end it 'does not blow up when given nil span and context' do @@ -58,18 +50,18 @@ assert true # nothing above raised an exception end it 'does not blow up when given a context that is not a Context' do - processor.on_start(@span, :not_a_context) + processor.on_start(span, :not_a_context) assert true # nothing above raised an exception end it 'does not blow up when given a span that is not a Span' do - processor.on_start(:not_a_span, @context_with_baggage) + processor.on_start(:not_a_span, context_with_baggage) assert true # nothing above raised an exception end end describe 'satisfies the SpanProcessor duck type with no-op methods' do it 'implements #on_finish' do - processor.on_finish(@span) + processor.on_finish(span) assert true # nothing above raised an exception end @@ -81,4 +73,23 @@ _(processor.shutdown).must_equal(OpenTelemetry::SDK::Trace::Export::SUCCESS) end end + + describe 'integration test with an exporter' do + let(:tracer) { OpenTelemetry.tracer_provider.tracer('🧳') } + let(:exporter) { TEST_EXPORTER } + + before do + exporter.reset + end + + it 'adds baggage attributes to spans' do + tracer + .start_span('integration test span', with_parent: context_with_baggage) + .finish + + _(exporter.finished_spans.size).must_equal(1) + _(exporter.finished_spans.first.name).must_equal('integration test span') + _(exporter.finished_spans.first.attributes).must_equal('a_key' => 'a_value') + end + end end