Class: OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber
- Inherits:
-
Object
- Object
- OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber
- Defined in:
- lib/opentelemetry/instrumentation/active_support/span_subscriber.rb
Constant Summary collapse
- ALWAYS_VALID_PAYLOAD_TYPES =
[TrueClass, FalseClass, String, Numeric, Symbol].freeze
Instance Method Summary collapse
-
#finish(name, id, payload) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(name:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: []) ⇒ SpanSubscriber
constructor
A new instance of SpanSubscriber.
- #start(name, id, payload) ⇒ Object
Constructor Details
#initialize(name:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: []) ⇒ SpanSubscriber
Returns a new instance of SpanSubscriber.
47 48 49 50 51 52 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 47 def initialize(name:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: []) @span_name = name.split('.')[0..1].reverse.join(' ').freeze @tracer = tracer @notification_payload_transform = notification_payload_transform @disallowed_notification_payload_keys = disallowed_notification_payload_keys end |
Instance Method Details
#finish(name, id, payload) ⇒ Object
rubocop:disable Metrics/AbcSize
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 67 def finish(name, id, payload) # rubocop:disable Metrics/AbcSize span = payload.delete(:__opentelemetry_span) token = payload.delete(:__opentelemetry_ctx_token) return unless span && token payload = transform_payload(payload) attrs = payload.map do |k, v| [k.to_s, sanitized_value(v)] if valid_payload_key?(k) && valid_payload_value?(v) end span.add_attributes(attrs.compact.to_h) 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
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opentelemetry/instrumentation/active_support/span_subscriber.rb', line 54 def start(name, id, payload) span = @tracer.start_span(@span_name, kind: :internal) token = OpenTelemetry::Context.attach( OpenTelemetry::Trace.context_with_span(span) ) payload.merge!( __opentelemetry_span: span, __opentelemetry_ctx_token: token ) [span, token] end |