Skip to content

Commit

Permalink
add an integration-ish test w/actual exporter
Browse files Browse the repository at this point in the history
Also, lean into spec's let.
  • Loading branch information
robbkidd committed Apr 22, 2024
1 parent 4f9ed3d commit 5b0397e
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,43 @@

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
processor.on_start(nil, nil)
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

Expand All @@ -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

0 comments on commit 5b0397e

Please sign in to comment.