Skip to content

Commit 7c8ab68

Browse files
committed
chore: exercise otel context with tracer_sampler
1 parent 9fe7fe4 commit 7c8ab68

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

sentry-opentelemetry/spec/sentry/opentelemetry/span_processor_spec.rb

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@
154154

155155
it 'starts a sentry transaction on otel root span' do
156156
expect(Sentry).to receive(:start_transaction).and_call_original
157-
expect_any_instance_of(Sentry::Transaction).to receive(:set_initial_sample_decision).with(
158-
sampling_context: a_hash_including(
159-
otel: {
160-
attributes: root_span.attributes,
161-
resource: root_span.resource.attribute_enumerator.to_h,
162-
kind: root_span.kind,
163-
instrumentation_scope: {
164-
name: root_span.instrumentation_scope.name,
165-
version: root_span.instrumentation_scope.version
166-
}
167-
}
168-
)
169-
)
170157

171158
subject.on_start(root_span, empty_context)
172159

@@ -189,6 +176,32 @@
189176
expect(transaction.baggage).to eq(nil)
190177
end
191178

179+
it 'includes otel context in custom sampling context' do
180+
sampling_context = nil
181+
Sentry.configuration.traces_sampler = lambda do |context|
182+
sampling_context = context
183+
0.5
184+
end
185+
186+
subject.on_start(root_span, empty_context)
187+
188+
expect(sampling_context).to include(:otel)
189+
otel_context = sampling_context[:otel]
190+
191+
expect(otel_context).to include(
192+
kind: root_span.kind,
193+
instrumentation_scope: {
194+
name: root_span.instrumentation_scope.name,
195+
version: root_span.instrumentation_scope.version
196+
}
197+
)
198+
199+
expect(otel_context).to include(attributes: root_span.attributes)
200+
201+
resource_attributes = root_span.resource.attribute_enumerator.to_h
202+
expect(otel_context).to include(resource: resource_attributes)
203+
end
204+
192205
context 'with started transaction' do
193206
let(:transaction) do
194207
subject.on_start(root_span, empty_context)

0 commit comments

Comments
 (0)