Class: PlainApm::Hooks::ActiveSupportSubscriber
- Inherits:
-
Object
- Object
- PlainApm::Hooks::ActiveSupportSubscriber
- Includes:
- EventAttributes
- Defined in:
- lib/plain_apm/hooks/active_support_subscriber.rb
Direct Known Subclasses
ActionMailer, ActionPack, ActionView, ActiveJob, ActiveRecord, ActiveSupport, Manual
Constant Summary
Constants included from EventAttributes
EventAttributes::IGNORED_EXCEPTIONS, EventAttributes::SOURCES_WITH_EXTRA_ATTRIBUTES
Instance Method Summary collapse
Methods included from EventAttributes
#attributes_from_exception, #attributes_from_notification
Instance Method Details
#collect(event) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/plain_apm/hooks/active_support_subscriber.rb', line 32 def collect(event) # drop immediately if there's no ongoing transaction return if PlainApm::Extensions::Context.trace_id.nil? # id / transaction_id is by instrumenter and thread payload = payload(event) return if payload.nil? ::PlainApm.agent.collect(payload) end |
#install ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/plain_apm/hooks/active_support_subscriber.rb', line 8 def install return unless defined?(::ActiveSupport::Notifications) asn = ::ActiveSupport::Notifications # Rails 6.0 has a slightly different arity check in the subscriber # constructor, so we need to use a proc, method(:collect) won't work. # https://github.com/rails/rails/blob/28bb76d3efc39b2ef663dfe2346f7c2621343cd6/activesupport/lib/active_support/notifications/fanout.rb#L93-L100 # vs # https://github.com/rails/rails/blob/7c70791470fc517deb7c640bead9f1b47efb5539/activesupport/lib/active_support/notifications/fanout.rb#L132-L139 subscriber = proc { |event| collect(event) } # #monotonic_subscribe got added in Rails >= 6.1 @subscription = if asn.respond_to?(:monotonic_subscribe) asn.monotonic_subscribe(notification_pattern, subscriber) else asn.subscribe(notification_pattern, subscriber) end end |
#uninstall ⇒ Object
28 29 30 |
# File 'lib/plain_apm/hooks/active_support_subscriber.rb', line 28 def uninstall ::ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription end |