Skip to content

Add support for metric name suffixes for distribution#73

Open
urxvtcd wants to merge 1 commit into
beam-telemetry:mainfrom
urxvtcd:distribution-suffixes
Open

Add support for metric name suffixes for distribution#73
urxvtcd wants to merge 1 commit into
beam-telemetry:mainfrom
urxvtcd:distribution-suffixes

Conversation

@urxvtcd
Copy link
Copy Markdown

@urxvtcd urxvtcd commented Jul 7, 2025

Hi there,

I know it's not A HUGE PROBLEM, the library does the job fine (thanks for your work!), but I noticed that the names of the metrics the distribution creates are not in line with recommendations from Prometheus docs. For any metric name given by the user, this library will append three suffixes: bucket, sum, and count. Let's consider something like handling an HTTP request.

If we go with http_request_duration_seconds, then http_request_duration_seconds_count looks weird.
If we go with http_request then count looks fine, but sum is off, and we don't follow the recommendation to include the unit in the bucket metric name.

So I tried to see if something can be done about it. What I came up with is allowing the user to include the suffixes to use in the reporter options. The metric definitions then looks like this:

distribution_reporter_options = [
  bucket_suffix: "duration_seconds",
  sum_suffix: "duration_seconds_total",
  count_suffix: "total",
  buckets: [
    0.005,
    0.010,
    # ...
  ]
]

Telemetry.Metrics.distribution(
  "http.request",
  event_name: "http.request.stop",
  measurement: :duration,
  unit: {:native, :second},
  description: "Total HTTP request handling time",
  reporter_options: distribution_reporter_options
),

Which results in this output:

http_request_duration_seconds{le="+Inf"} 111
http_request_duration_seconds_total 0.010809296000000003
http_request_total 111

The PR only includes the bare minimum of code to make it work (no validation, no docs), because I just wanted to ask if this is something you'd be interested in.

Best regards

@urxvtcd urxvtcd requested a review from bryannaegele as a code owner July 7, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant