Skip to content

Commit 5b0397e

Browse files
committed
add an integration-ish test w/actual exporter
Also, lean into spec's let.
1 parent 4f9ed3d commit 5b0397e

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb

+29-18
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,43 @@
2525

2626
describe OpenTelemetry::Processor::Baggage::BaggageSpanProcessor do
2727
let(:processor) { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new }
28-
let(:exporter) { TEST_EXPORTER }
29-
30-
before do
31-
exporter.reset
32-
end
28+
let(:span) { Minitest::Mock.new }
29+
let(:context_with_baggage) { OpenTelemetry::Baggage.set_value('a_key', 'a_value') }
3330

3431
describe '#on_start' do
35-
before do
36-
@span = Minitest::Mock.new
37-
@context_with_baggage = OpenTelemetry::Baggage.set_value('a_key', 'a_value')
38-
end
39-
4032
it 'adds current baggage keys/values as attributes when a span starts' do
41-
@span.expect(:add_attributes, @span, [{ 'a_key' => 'a_value' }])
33+
span.expect(:add_attributes, span, [{ 'a_key' => 'a_value' }])
4234

43-
processor.on_start(@span, @context_with_baggage)
35+
processor.on_start(span, context_with_baggage)
4436

45-
@span.verify
37+
span.verify
4638
end
4739

4840
it 'does not blow up when given nil context' do
49-
processor.on_start(@span, nil)
41+
processor.on_start(span, nil)
5042
assert true # nothing above raised an exception
5143
end
5244
it 'does not blow up when given nil span' do
53-
processor.on_start(nil, @context_with_baggage)
45+
processor.on_start(nil, context_with_baggage)
5446
assert true # nothing above raised an exception
5547
end
5648
it 'does not blow up when given nil span and context' do
5749
processor.on_start(nil, nil)
5850
assert true # nothing above raised an exception
5951
end
6052
it 'does not blow up when given a context that is not a Context' do
61-
processor.on_start(@span, :not_a_context)
53+
processor.on_start(span, :not_a_context)
6254
assert true # nothing above raised an exception
6355
end
6456
it 'does not blow up when given a span that is not a Span' do
65-
processor.on_start(:not_a_span, @context_with_baggage)
57+
processor.on_start(:not_a_span, context_with_baggage)
6658
assert true # nothing above raised an exception
6759
end
6860
end
6961

7062
describe 'satisfies the SpanProcessor duck type with no-op methods' do
7163
it 'implements #on_finish' do
72-
processor.on_finish(@span)
64+
processor.on_finish(span)
7365
assert true # nothing above raised an exception
7466
end
7567

@@ -81,4 +73,23 @@
8173
_(processor.shutdown).must_equal(OpenTelemetry::SDK::Trace::Export::SUCCESS)
8274
end
8375
end
76+
77+
describe 'integration test with an exporter' do
78+
let(:tracer) { OpenTelemetry.tracer_provider.tracer('🧳') }
79+
let(:exporter) { TEST_EXPORTER }
80+
81+
before do
82+
exporter.reset
83+
end
84+
85+
it 'adds baggage attributes to spans' do
86+
tracer
87+
.start_span('integration test span', with_parent: context_with_baggage)
88+
.finish
89+
90+
_(exporter.finished_spans.size).must_equal(1)
91+
_(exporter.finished_spans.first.name).must_equal('integration test span')
92+
_(exporter.finished_spans.first.attributes).must_equal('a_key' => 'a_value')
93+
end
94+
end
8495
end

0 commit comments

Comments
 (0)