|
25 | 25 |
|
26 | 26 | describe OpenTelemetry::Processor::Baggage::BaggageSpanProcessor do
|
27 | 27 | 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') } |
33 | 30 |
|
34 | 31 | 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 |
| - |
40 | 32 | 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' }]) |
42 | 34 |
|
43 |
| - processor.on_start(@span, @context_with_baggage) |
| 35 | + processor.on_start(span, context_with_baggage) |
44 | 36 |
|
45 |
| - @span.verify |
| 37 | + span.verify |
46 | 38 | end
|
47 | 39 |
|
48 | 40 | it 'does not blow up when given nil context' do
|
49 |
| - processor.on_start(@span, nil) |
| 41 | + processor.on_start(span, nil) |
50 | 42 | assert true # nothing above raised an exception
|
51 | 43 | end
|
52 | 44 | 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) |
54 | 46 | assert true # nothing above raised an exception
|
55 | 47 | end
|
56 | 48 | it 'does not blow up when given nil span and context' do
|
57 | 49 | processor.on_start(nil, nil)
|
58 | 50 | assert true # nothing above raised an exception
|
59 | 51 | end
|
60 | 52 | 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) |
62 | 54 | assert true # nothing above raised an exception
|
63 | 55 | end
|
64 | 56 | 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) |
66 | 58 | assert true # nothing above raised an exception
|
67 | 59 | end
|
68 | 60 | end
|
69 | 61 |
|
70 | 62 | describe 'satisfies the SpanProcessor duck type with no-op methods' do
|
71 | 63 | it 'implements #on_finish' do
|
72 |
| - processor.on_finish(@span) |
| 64 | + processor.on_finish(span) |
73 | 65 | assert true # nothing above raised an exception
|
74 | 66 | end
|
75 | 67 |
|
|
81 | 73 | _(processor.shutdown).must_equal(OpenTelemetry::SDK::Trace::Export::SUCCESS)
|
82 | 74 | end
|
83 | 75 | 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 |
84 | 95 | end
|
0 commit comments