Class: Sentry::OpenTelemetry::SpanProcessor
- Inherits:
-
OpenTelemetry::SDK::Trace::SpanProcessor
- Object
- OpenTelemetry::SDK::Trace::SpanProcessor
- Sentry::OpenTelemetry::SpanProcessor
- Includes:
- Singleton
- Defined in:
- lib/sentry/opentelemetry/span_processor.rb
Constant Summary collapse
- SEMANTIC_CONVENTIONS =
::OpenTelemetry::SemanticConventions::Trace
- INTERNAL_SPAN_KINDS =
i[client internal]
- SPAN_ORIGIN =
"auto.otel"
Instance Attribute Summary collapse
-
#span_map ⇒ Hash
readonly
The mapping from otel span ids to sentry spans.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ SpanProcessor
constructor
A new instance of SpanProcessor.
- #on_finish(otel_span) ⇒ Object
- #on_start(otel_span, parent_context) ⇒ Object
Constructor Details
#initialize ⇒ SpanProcessor
Returns a new instance of SpanProcessor.
20 21 22 23 |
# File 'lib/sentry/opentelemetry/span_processor.rb', line 20 def initialize @span_map = {} setup_event_processor end |
Instance Attribute Details
#span_map ⇒ Hash (readonly)
The mapping from otel span ids to sentry spans
18 19 20 |
# File 'lib/sentry/opentelemetry/span_processor.rb', line 18 def span_map @span_map end |
Instance Method Details
#clear ⇒ Object
76 77 78 |
# File 'lib/sentry/opentelemetry/span_processor.rb', line 76 def clear @span_map = {} end |
#on_finish(otel_span) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sentry/opentelemetry/span_processor.rb', line 60 def on_finish(otel_span) return unless Sentry.initialized? && Sentry.configuration.instrumenter == :otel return unless otel_span.context.valid? sentry_span = @span_map.delete(otel_span.context.hex_span_id) return unless sentry_span if sentry_span.is_a?(Sentry::Transaction) update_transaction_with_otel_data(sentry_span, otel_span) else update_span_with_otel_data(sentry_span, otel_span) end sentry_span.finish(end_timestamp: otel_span. / 1e9) end |
#on_start(otel_span, parent_context) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sentry/opentelemetry/span_processor.rb', line 25 def on_start(otel_span, parent_context) return unless Sentry.initialized? && Sentry.configuration.instrumenter == :otel return unless otel_span.context.valid? return if from_sentry_sdk?(otel_span) trace_data = get_trace_data(otel_span, parent_context) sentry_parent_span = @span_map[trace_data.parent_span_id] if trace_data.parent_span_id sentry_span = if sentry_parent_span sentry_parent_span.start_child( span_id: trace_data.span_id, description: otel_span.name, start_timestamp: otel_span. / 1e9, origin: SPAN_ORIGIN ) else = { instrumenter: :otel, name: otel_span.name, span_id: trace_data.span_id, trace_id: trace_data.trace_id, parent_span_id: trace_data.parent_span_id, parent_sampled: trace_data.parent_sampled, baggage: trace_data.baggage, start_timestamp: otel_span. / 1e9, origin: SPAN_ORIGIN } Sentry.start_transaction(**) end @span_map[trace_data.span_id] = sentry_span end |