Module: Honeycomb::ActiveSupport::Configuration
- Included in:
- Configuration
- Defined in:
- lib/honeycomb/integrations/active_support.rb
Overview
Included in the configuration object to specify events that should be subscribed to
Instance Attribute Summary collapse
Instance Method Summary collapse
- #active_support_handlers ⇒ Object
- #after_initialize(client) ⇒ Object
- #default_handler ⇒ Object
- #handle_notification_event(name, span, payload) ⇒ Object
- #on_notification_event(event_name = nil, &hook) ⇒ Object
Instance Attribute Details
#notification_events ⇒ Object
43 44 45 |
# File 'lib/honeycomb/integrations/active_support.rb', line 43 def notification_events @notification_events ||= [] end |
Instance Method Details
#active_support_handlers ⇒ Object
39 40 41 |
# File 'lib/honeycomb/integrations/active_support.rb', line 39 def active_support_handlers @active_support_handlers ||= {} end |
#after_initialize(client) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/honeycomb/integrations/active_support.rb', line 13 def after_initialize(client) super(client) if defined?(super) events = notification_events | active_support_handlers.keys ActiveSupport::Subscriber.new(client: client).tap do |sub| events.each do |event| sub.subscribe(event, &method(:handle_notification_event)) end end end |
#default_handler ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/honeycomb/integrations/active_support.rb', line 47 def default_handler @default_handler ||= lambda do |name, span, payload| payload.each do |key, value| # Make ActionController::Parameters parseable by libhoney. value = value.to_unsafe_hash if value.respond_to?(:to_unsafe_hash) span.add_field("#{name}.#{key}", value) end # If the notification event has recorded an exception, add the # Beeline's usual error fields to the span. # * Uses the 2-element array on :exception in the event payload # to support Rails 4. If Rails 4 support is dropped, consider # the :exception_object added in Rails 5. error, error_detail = payload[:exception] span.add_field("error", error) if error span.add_field("error_detail", error_detail) if error_detail end end |
#handle_notification_event(name, span, payload) ⇒ Object
33 34 35 36 37 |
# File 'lib/honeycomb/integrations/active_support.rb', line 33 def handle_notification_event(name, span, payload) handler = active_support_handlers.fetch(name, default_handler) handler.call(name, span, payload) end |
#on_notification_event(event_name = nil, &hook) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/honeycomb/integrations/active_support.rb', line 25 def on_notification_event(event_name = nil, &hook) if event_name active_support_handlers[event_name] = hook else @default_handler = hook end end |