class Honeycomb::ActiveSupport::Subscriber

Handles ActiveSupport::Notification subscriptions, relaying them to a Honeycomb client

Attributes

client[R]
handlers[R]
key[R]

Public Class Methods

new(client:) click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 70
def initialize(client:)
  @client = client
  @handlers = {}
  @key = ["honeycomb", self.class.name, object_id].join("-")
end

Public Instance Methods

finish(name, id, payload) click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 87
def finish(name, id, payload)
  return unless (span = spans[id].pop)

  handler_for(name).call(name, span, payload)

  span.send
end
start(name, id, _payload) click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 83
def start(name, id, _payload)
  spans[id] << client.start_span(name: name)
end
subscribe(event, &block) click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 76
def subscribe(event, &block)
  return unless block_given?

  handlers[event] = block
  ::ActiveSupport::Notifications.subscribe(event, self)
end

Private Instance Methods

handler_for(name) click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 103
def handler_for(name)
  handlers.fetch(name) do
    handlers[
      handlers.keys.detect do |key|
        key.is_a?(Regexp) && key =~ name
      end
    ]
  end
end
spans() click to toggle source
# File lib/honeycomb/integrations/active_support.rb, line 99
def spans
  Thread.current[key] ||= Hash.new { |h, id| h[id] = [] }
end