class HubStep::Instrumenter

Wrapper around ActiveSupport::Notifications (or any object with the same API) that traces instrumented blocks. Behaves identically to the underlying object except that blocks passed to instrument will be passed two arguments instead of one: the payload Hash (as usual) and the Span that will represent this block of code in the trace. The Span can be used to set tags etc.

require "hubstep/instrumenter"

instrumenter = HubStep::Instrumenter.new(tracer, ActiveSupport::Notifications)

def deflate(data)
  # This block will be recorded as a span by the tracer and will also
  # generate a notification as usual.
  instrumenter.instrument("deflate.zlib") do |payload, span|
    span.set_tag("bytesize", data.bytesize)
    Zlib::Deflate.deflate(data)
  end
end

Attributes

service[R]

Public Class Methods

new(tracer, service) click to toggle source

Creates an Instrumenter

tracer - HubStep::Tracer instance service - Object that provides ActiveSupport::Notifications' API (i.e.,

you could just pass ActiveSupport::Notifications here, or wrap
it in some other object).
# File lib/hubstep/instrumenter.rb, line 30
def initialize(tracer, service)
  @tracer = tracer
  @service = service
end

Public Instance Methods

instrument(name, payload = {}) { |inner_payload, span| ... } click to toggle source
# File lib/hubstep/instrumenter.rb, line 39
def instrument(name, payload = {})
  @tracer.span(name) do |span|
    service.instrument(name, payload) do |inner_payload|
      yield inner_payload, span if block_given?
    end
  end
end
publish(name, *args) click to toggle source
# File lib/hubstep/instrumenter.rb, line 35
def publish(name, *args)
  service.publish(name, *args)
end
subscribe(*args, &block) click to toggle source
# File lib/hubstep/instrumenter.rb, line 47
def subscribe(*args, &block)
  service.subscribe(*args, &block)
end
subscribed(callback, *args, &block) click to toggle source
# File lib/hubstep/instrumenter.rb, line 51
def subscribed(callback, *args, &block)
  service.subscribed(callback, *args, &block)
end
unsubscribe(args) click to toggle source
# File lib/hubstep/instrumenter.rb, line 55
def unsubscribe(args)
  service.unsubscribe(args)
end