Class: Honeycomb::ActiveSupport::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/honeycomb/integrations/active_support.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Subscriber

Returns a new instance of Subscriber.



70
71
72
73
74
# File 'lib/honeycomb/integrations/active_support.rb', line 70

def initialize(client:)
  @client = client
  @handlers = {}
  @key = ["honeycomb", self.class.name, object_id].join("-")
end

Instance Method Details

#finish(name, id, payload) ⇒ Object



87
88
89
90
91
92
93
# 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) ⇒ Object



83
84
85
# 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) ⇒ Object



76
77
78
79
80
81
# 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