Telemetry metrics how to increment counter by a given amount?

I think I’ve figured it out, I’ve tested it as well so it worked.

We are using telemetry_metrics_statsd as the reporter and from its docs regarding the counter metric:

Note that the counter was bumped by 1, regardless of the measurements included in the event (careful reader will notice that the :count measurement we chose for the metric wasn’t present in the map of measurements at all!). Such behaviour conforms to the specification of counter as defined by Telemetry.Metrics package - a counter should be incremented by 1 every time a given event is dispatched.

What I should’ve used instead is the sum metric:

Sum metric is also represented as a gauge - the difference is that it always changes relatively and is never set to an absolute value. Given metric definition below

So I’ve changed this

counter("my_app.jobs.count", tags: [:status]),

into this:

sum("my_app.jobs.count",
  tags: [:status],
  reporter_options: [report_as: :counter]
)

I think I should’ve mentioned that in my question to start with, but I didn’t know it could be related. Sorry for that.

3 Likes