Skip to content

Commit

Permalink
Add event processor in OpenTelemetry SpanProcessor to link errors and…
Browse files Browse the repository at this point in the history
… transactions
  • Loading branch information
sl0thentr0py committed Jan 9, 2023
1 parent b73abea commit 74c5ef6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 74c5ef6

Please sign in to comment.