interagent / pliny

An opinionated toolkit for writing excellent APIs in Ruby.
MIT License
802 stars 73 forks source link

Pliny::Metrics.measure value argument #288

Closed joshwlewis closed 7 years ago

joshwlewis commented 7 years ago

Many times, the operation you want to measure is not block execution time. You may want to measure something that is already stored as a variable. This is a common pattern for us, and we commonly do this:

      queue = ::Sidekiq::Queue.new

      Pliny.log(
        "app.sidekiq.latency" => queue.latency,
        "app.sidekiq.depth" => queue.depth
      )

You can see here that we're leaning on l2met logging, but with the new pluggable metrics backends, it'd be much nicer to be able to do something like:

Pliny::Metrics.measure("app.sidekiq.latency", queue.latency)

Right now, measure only reports execution time of the provided block. This PR proposes that the block becomes optional and if provided, the :value option takes precedence.

This should provide a symmetry between the two methods, e.g.:

Pliny::Metrics.count(:foo, value: 3)
Pliny::Metrics.measure(:bar, value: 3.14)

But should also maintain the current API of:

Pliny::Metrics.measure(:qux) { # some long running work }
gudmundur commented 7 years ago

Nice work @joshwlewis!