Sha256: c2d05c872e683d7dcb6ee3bb302e60548cda7938825c0a8f522a0a0d11e9dba1
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
# frozen_string_literal: true # Copyright The OpenTelemetry Authors # # SPDX-License-Identifier: Apache-2.0 module OpenTelemetry module Instrumentation module ActionView # This is a replacement for the default Fanout notifications queue, which adds special # handling around returned context from the SpanSubscriber notification handlers. # Used together, it allows us to trace arbitrary ActiveSupport::Notifications safely. class Fanout < ::ActiveSupport::Notifications::Fanout def start(name, id, payload) listeners_for(name).map do |s| result = [s] state = s.start(name, id, payload) if state.is_a?(Array) && state[0].is_a?(OpenTelemetry::Trace::Span) && state[1] # rubocop:disable Style/IfUnlessModifier result << state end result end end def finish(name, id, payload, listeners = listeners_for(name)) listeners.each do |(s, arr)| span, token = arr if span.is_a?(OpenTelemetry::Trace::Span) && token s.finish( name, id, payload.merge( __opentelemetry_span: span, __opentelemetry_ctx_token: token ) ) else s.finish(name, id, payload) end end end def listeners_for(name) listeners = super listeners.sort_by do |l| l.instance_variable_get(:@delegate).is_a?(SpanSubscriber) ? -1 : 1 end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
opentelemetry-instrumentation-action_view-0.1.0 | lib/opentelemetry/instrumentation/action_view/fanout.rb |