Class: OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber
- Inherits:
-
Object
- Object
- OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber
- Defined in:
- lib/opentelemetry/instrumentation/active_support/span_subscriber.rb
Overview
rubocop:enable Metrics/ParameterLists
Constant Summary collapse
- ALWAYS_VALID_PAYLOAD_TYPES =
[TrueClass, FalseClass, String, Numeric, Symbol].freeze
Instance Method Summary collapse
- #finish(name, id, payload) ⇒ Object
-
#initialize(pattern:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: nil, kind: nil, span_name_formatter: nil) ⇒ SpanSubscriber
constructor
rubocop:disable Metrics/ParameterLists.
-
#start(name, id, payload) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Constructor Details
#initialize(pattern:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: nil, kind: nil, span_name_formatter: nil) ⇒ SpanSubscriber
rubocop:disable Metrics/ParameterLists
67 68 69 70 71 72 73 74 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 67 def initialize(pattern:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: nil, kind: nil, span_name_formatter: nil) @pattern = pattern @tracer = tracer @notification_payload_transform = notification_payload_transform @disallowed_notification_payload_keys = Array(disallowed_notification_payload_keys) @kind = kind || :internal @span_name_formatter = span_name_formatter end |
Instance Method Details
#finish(name, id, payload) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 88 def finish(name, id, payload) span = payload.delete(:__opentelemetry_span) token = payload.delete(:__opentelemetry_ctx_token) return unless span && token attrs = transform_payload(payload).each_with_object({}) do |(k, v), accum| accum[k.to_s] = sanitized_value(v) if valid_payload_key?(k) && valid_payload_value?(v) end span.add_attributes(attrs) if (e = payload[:exception_object]) span.record_exception(e) span.status = OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{e.class}") end span.finish OpenTelemetry::Context.detach(token) end |
#start(name, id, payload) ⇒ Object
rubocop:enable Metrics/ParameterLists
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 77 def start(name, id, payload) span = @tracer.start_span(safe_span_name_for(name), kind: @kind) token = OpenTelemetry::Context.attach( OpenTelemetry::Trace.context_with_span(span) ) payload[:__opentelemetry_span] = span payload[:__opentelemetry_ctx_token] = token [span, token] end |