Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def on_start(otel_span, parent_context)
parent_sampled: trace_data.parent_sampled,
baggage: trace_data.baggage,
start_timestamp: otel_span.start_timestamp / 1e9,
origin: SPAN_ORIGIN
origin: SPAN_ORIGIN,
custom_sampling_context: {
otel: otel_context_hash(otel_span).merge(
kind: otel_span.kind,
instrumentation_scope: {
name: otel_span.instrumentation_scope.name,
version: otel_span.instrumentation_scope.version
}
)
}
}

Sentry.start_transaction(**options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@

it 'starts a sentry transaction on otel root span' do
expect(Sentry).to receive(:start_transaction).and_call_original

subject.on_start(root_span, empty_context)

span_id = root_span.context.hex_span_id
Expand All @@ -175,6 +176,32 @@
expect(transaction.baggage).to eq(nil)
end

it 'includes otel context in custom sampling context' do
sampling_context = nil
Sentry.configuration.traces_sampler = lambda do |context|
sampling_context = context
0.5
end

subject.on_start(root_span, empty_context)

expect(sampling_context).to include(:otel)
otel_context = sampling_context[:otel]

expect(otel_context).to include(
kind: root_span.kind,
instrumentation_scope: {
name: root_span.instrumentation_scope.name,
version: root_span.instrumentation_scope.version
}
)

expect(otel_context).to include(attributes: root_span.attributes)

resource_attributes = root_span.resource.attribute_enumerator.to_h
expect(otel_context).to include(resource: resource_attributes)
end

context 'with started transaction' do
let(:transaction) do
subject.on_start(root_span, empty_context)
Expand Down
Loading