Skip to content

Easier way to specify histogram boundaries? #3619

@nwalters512

Description

@nwalters512

NB: Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.

Is your feature request related to a problem? Please describe.

It's currently somewhat unergonomic to create a histogram with custom buckets/boundaries. Because this must be done with Views, and because Views can only be provided when a MeterProvider is created, this means that the boundary configuration for a histogram must live in a completely separate part of the codebase from the createHistogram call itself. In most cases I can imagine, the buckets for a given histogram are going to be tightly coupled to what individual histograms are measuring. For example, the boundaries for a histogram tracking SQL query duration are likely to be very different from the boundaries for a histogram tracking average response size, and in both cases I'd like to specify those boundaries when I'm creating the histogram metric.

Describe the solution you'd like

I'd like to be able to define a histogram's boundaries when I call createHistogram.

Per #2999, it looks like this used to be supported by the API, though I understand that this was removed in favor of using a View.

If a View is the way to go, perhaps it would be possible to provide a View in the call to createHistogram? Maybe something like this:

meter.createHistogram('foo.duration', {
  view: new View({
    aggregation: new ExplicitBucketHistogramAggregation([0, 1, 5, 10, 15, 20, 25, 30]),
  }),
});

Alternatively, one could directly provide an aggregation and a View would be transparently create for the metric:

meter.createHistogram('foo.duration', {
  aggregation: new ExplicitBucketHistogramAggregation([0, 1, 5, 10, 15, 20, 25, 30]),
});

Describe alternatives you've considered

AFAICT, there aren't any currently viable alternatives to creating a View alongside a MeterProvider

Additional context

This feature would make it possible to easily share and reuse histogram metrics via libraries. This would be really useful for e.g. building a library that can capture common Node metrics, including a histogram for GC duration with bucket sizes that have a sensible default. I'm thinking about something akin to this from the Prometheus world: https://github.com/siimon/prom-client/blob/8d6456c05f0708fed34628da5bd6f492a0ab43f8/lib/metrics/gc.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions