Class: Phlex::Reactive::APM::Subscriber
- Inherits:
-
Object
- Object
- Phlex::Reactive::APM::Subscriber
- Defined in:
- lib/phlex/reactive/apm/subscriber.rb
Overview
The ASN-driven half of the APM integration (issue #207). Subscribes to
action.phlex_reactive / defer.phlex_reactive and hands each event's
name-only payload + duration to the resolved adapter's record_action —
so the APM names the transaction Component#action and tags the outcome.
A plain ActiveSupport::Notifications subscriber (NOT a LogSubscriber): a LogSubscriber dispatches by the FULL event method, but we want the SAME record_action for both action and defer events and to hold a reference to the adapter instance. install/uninstall manage exactly one subscription so a re-attach with the same adapter never double-reports.
Constant Summary collapse
- EVENTS =
The events whose duration+outcome we forward to the APM as a named transaction. render/broadcast are left to the app (a Datadog child-span adapter can subscribe to them itself) — the action IS the transaction.
/\A(?:action|defer)\.phlex_reactive\z/
Class Method Summary collapse
-
.install(adapter) ⇒ Object
Install a single bus subscription for
adapter. - .installed? ⇒ Boolean
- .uninstall ⇒ Object
Instance Method Summary collapse
-
#call(event) ⇒ Object
(also: #action, #defer)
Route an already-built Event to record_action.
-
#initialize(adapter) ⇒ Subscriber
constructor
A new instance of Subscriber.
Constructor Details
#initialize(adapter) ⇒ Subscriber
Returns a new instance of Subscriber.
46 47 48 |
# File 'lib/phlex/reactive/apm/subscriber.rb', line 46 def initialize(adapter) @adapter = adapter end |
Class Method Details
.install(adapter) ⇒ Object
Install a single bus subscription for adapter. Idempotent for the
SAME adapter: a repeat call is a no-op. A DIFFERENT adapter replaces
the previous subscription (an app that swaps apm at boot wins last).
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/phlex/reactive/apm/subscriber.rb', line 26 def install(adapter) return if @adapter.equal?(adapter) && @subscription uninstall @adapter = adapter subscriber = new(adapter) @subscription = ::ActiveSupport::Notifications.subscribe(EVENTS) do |*args| subscriber.call(::ActiveSupport::Notifications::Event.new(*args)) end end |
.installed? ⇒ Boolean
43 |
# File 'lib/phlex/reactive/apm/subscriber.rb', line 43 def installed? = !@subscription.nil? |
.uninstall ⇒ Object
37 38 39 40 41 |
# File 'lib/phlex/reactive/apm/subscriber.rb', line 37 def uninstall ::ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription @subscription = nil @adapter = nil end |
Instance Method Details
#call(event) ⇒ Object Also known as: action, defer
Route an already-built Event to record_action. Named after the event's leading segment (action/defer) so the synthesized-event unit spec can call subscriber.action(event) exactly like the LogSubscriber spec.
53 54 55 |
# File 'lib/phlex/reactive/apm/subscriber.rb', line 53 def call(event) @adapter.record_action(event.payload, event.duration) end |