honeybadger-io / honeybadger-ruby

Ruby gem for reporting errors to honeybadger.io
https://docs.honeybadger.io/lib/ruby/
MIT License
250 stars 146 forks source link

feat: implement metric registry for aggregation #548

Closed roelbondoc closed 5 months ago

roelbondoc commented 5 months ago

This adds metrics aggregation.

New Components

Honeybadger::Registry - This class stores all tracked metrics registered in the gem. The registry ensures that only one instance of each unique metric is stored at any time. A metric is defined as unique by it's type, name, and set of attributes.

Honeybadger::RegistryExecution - This class is injected into the CollectorWorker and is run on a configurable interval. When called, it iterates over all registered metrics, compiles payloads for each, and sent as an event. The registry is then flushed.

Honeybadger::Metric - A base metric class from which all other metric classes inherit from. These metric classes record data and compute/track values as needed.

Shape of the Data

Each metric type's data is shaped differently. Below are examples of what that data looks like for each type.

counter

{
  "counter": 1
}

gauge

{
  "min": 1,
  "max": 10,
  "avg": 5.0,
  "latest": 5
}

timer

{
  "min": 1,
  "max": 10,
  "avg": 5.0,
  "latest": 5
}

Note: This may look the same as a gauge, however, the interface to use the metric provides a timing mechanism.

histogram

{
  "bins": {
    "10": 1,
    "50": 10,
    "100": 5
  }
}

Before submitting a pull request, please make sure the following is done:

  1. If you've fixed a bug or added code that should be tested, add tests!
  2. Run rake spec in the repository root.
  3. Use a pull request title that conforms to conventional commits.
roelbondoc commented 5 months ago

This is ready for review. I'll need to write some tests for this, which I'll do either in this PR, or the parent insights-events-instrumentation branch.

roelbondoc commented 5 months ago

This LGTM. Have you considered adding a decrement_counter to pair with increment_counter?

Ah yes, let me add that.

roelbondoc commented 5 months ago

I'm going to merge this in so there is only one branch. Feel free to comment here, or https://github.com/honeybadger-io/honeybadger-ruby/pull/539