diff --git a/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb b/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb index 89929d4a4..da78e383e 100644 --- a/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb +++ b/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb @@ -18,6 +18,7 @@ class SpanProcessor < ::OpenTelemetry::SDK::Trace::SpanProcessor def initialize @span_map = {} + setup_event_processor end def on_start(otel_span, parent_context) @@ -152,6 +153,19 @@ def update_span_with_otel_data(sentry_span, otel_span) sentry_span.set_op(op) sentry_span.set_description(description) end + + def setup_event_processor + Sentry.add_global_event_processor do |event, _hint| + span_context = ::OpenTelemetry::Trace.current_span.context + next event unless span_context.valid? + + sentry_span = @span_map[span_context.hex_span_id] + next event unless sentry_span + + event.contexts[:trace] ||= sentry_span.get_trace_context + event + end + end end end end