Method: Datadog::Statsd#distribution_time

Defined in:
lib/datadog/statsd.rb

#distribution_time(stat, opts = EMPTY_OPTIONS) ⇒ Object

Reports execution time of the provided block as a distribution.

If the block fails, the stat is still reported, then the error is reraised

Examples:

Report the time (in ms) taken to activate an account

$statsd.distribution_time('account.activate') { @account.activate! }

Parameters:

  • stat name.

  • distribution value.

  • (defaults to: EMPTY_OPTIONS)

    the options to create the metric with

Options Hash (opts):

  • :sample_rate (Numeric)

    sample rate, 1 for always

  • :tags (Array<String>)

    An array of tags

  • :cardinality (String)

    The tag cardinality to use



288
289
290
291
292
293
294
# File 'lib/datadog/statsd.rb', line 288

def distribution_time(stat, opts = EMPTY_OPTIONS)
  opts = { sample_rate: opts } if opts.is_a?(Numeric)
  start = now
  yield
ensure
  distribution(stat, ((now - start) * 1000).round, opts)
end