module Honeycomb::ActiveSupport::Configuration

Included in the configuration object to specify events that should be subscribed to

Attributes

notification_events[W]

Public Instance Methods

active_support_handlers() click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 39
def active_support_handlers
  @active_support_handlers ||= {}
end
after_initialize(client) click to toggle source
Calls superclass method
# 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() click to toggle source
# 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) click to toggle source
# 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
notification_events() click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 43
def notification_events
  @notification_events ||= []
end
on_notification_event(event_name = nil, &hook) click to toggle source
# 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