module Honeybadger::InstrumentationHelper
Honeybadger::InstrumentationHelper
is a module that can be included into any class. This module provides a convenient DSL around the instrumentation methods to provide a cleaner interface. There are three usage variations as show in the example below:
@example class TicketsController < ApplicationController include Honeybadger::InstrumentationHelper
def create metric_source 'controller' metric_attributes(foo: 'bar') # These attributes get tagged to all metrics called after. # pass a block time('create.ticket') { Ticket.create(params[:ticket]) } # pass a lambda argument time 'create.ticket', ->{ Ticket.create(params[:ticket]) } # pass the duration argument duration = timing_method { Ticket.create(params[:ticket]) } time 'create.ticket', duration: duration end end
Public Instance Methods
Source
# File lib/honeybadger/instrumentation_helper.rb, line 88 def decrement_counter(name, *args) attributes = extract_attributes(args) callable = extract_callable(args) if callable metric_instrumentation.decrement_counter(name, attributes, ->{ callable.call }) elsif block_given? metric_instrumentation.decrement_counter(name, attributes, ->{ yield }) else metric_instrumentation.decrement_counter(name, attributes) end end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 113 def extract_attributes(args) attributes = metric_instrumentation.extract_attributes(args) attributes.merge(metric_source: @metric_source).merge(@metric_attributes || {}).compact end
@api private
Source
# File lib/honeybadger/instrumentation_helper.rb, line 119 def extract_callable(args) metric_instrumentation.extract_callable(args) end
@api private
Source
# File lib/honeybadger/instrumentation_helper.rb, line 100 def gauge(name, *args) attributes = extract_attributes(args) callable = extract_callable(args) if callable metric_instrumentation.gauge(name, attributes, ->{ callable.call }) elsif block_given? metric_instrumentation.gauge(name, attributes, ->{ yield }) else metric_instrumentation.gauge(name, attributes) end end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 64 def histogram(name, *args) attributes = extract_attributes(args) callable = extract_callable(args) if callable metric_instrumentation.histogram(name, attributes, ->{ callable.call }) elsif block_given? metric_instrumentation.histogram(name, attributes, ->{ yield }) else metric_instrumentation.histogram(name, attributes) end end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 76 def increment_counter(name, *args) attributes = extract_attributes(args) callable = extract_callable(args) if callable metric_instrumentation.increment_counter(name, attributes, ->{ callable.call }) elsif block_given? metric_instrumentation.increment_counter(name, attributes, ->{ yield }) else metric_instrumentation.increment_counter(name, attributes) end end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 39 def metric_agent(agent) @metric_agent = agent end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 47 def metric_attributes(attributes) raise "metric_attributes expects a hash" unless attributes.is_a?(Hash) @metric_attributes = attributes end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 43 def metric_instrumentation @metric_instrumentation ||= @metric_agent ? Honeybadger::Instrumentation.new(@metric_agent) : Honeybadger.instrumentation end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 35 def metric_source(source) @metric_source = source end
Source
# File lib/honeybadger/instrumentation_helper.rb, line 31 def monotonic_timer metric_instrumentation.monotonic_timer { yield } end
returns two parameters, the first is the duration of the execution, and the second is the return value of the passed block
Source
# File lib/honeybadger/instrumentation_helper.rb, line 52 def time(name, *args) attributes = extract_attributes(args) callable = extract_callable(args) if callable metric_instrumentation.time(name, attributes, ->{ callable.call }) elsif block_given? metric_instrumentation.time(name, attributes, ->{ yield }) else metric_instrumentation.time(name, attributes) end end