Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier way to specify histogram boundaries? #3619

Closed
nwalters512 opened this issue Feb 16, 2023 · 7 comments · Fixed by #3876
Closed

Easier way to specify histogram boundaries? #3619

nwalters512 opened this issue Feb 16, 2023 · 7 comments · Fixed by #3876
Labels
api:metrics Issues and PRs related to the Metrics API feature-request

Comments

@nwalters512
Copy link

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.

@weyert
Copy link
Contributor

weyert commented Feb 17, 2023

You might find this spec proposal interesting:
open-telemetry/opentelemetry-specification#3216

@krutoo
Copy link

krutoo commented Mar 31, 2023

Сan someone tell me how to at least somehow set buckets for histogram now?

@weyert
Copy link
Contributor

weyert commented Mar 31, 2023

You need to define a View for it before the instruments are created

@weyert
Copy link
Contributor

weyert commented Mar 31, 2023

new View({
aggregation: new ExplicitBucketHistogramAggregation([1,5,10,25], true),
instrumentName: metricName,
instrumentType: InstrumentType.HISTOGRAM,
})

@krutoo
Copy link

krutoo commented Mar 31, 2023

new View({ aggregation: new ExplicitBucketHistogramAggregation([1,5,10,25], true), instrumentName: metricName, instrumentType: InstrumentType.HISTOGRAM, })

thanks but in unit test we found other way to achieve it:

it('with instrument unit should apply view to only the selected instrument unit', async () => {

Opentelemetry is really great framework but looks like some cases are too complex here

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jun 5, 2023
@legendecas legendecas linked a pull request Jun 8, 2023 that will close this issue
5 tasks
@legendecas legendecas added the api:metrics Issues and PRs related to the Metrics API label Jun 8, 2023
@github-actions github-actions bot removed the stale label Jun 12, 2023
@jdmarshall
Copy link

Hmm, I think I had this suggestion working and now it's stopped. Is the metricName required? I thought I read that for instance just a units label would be enough. (eg, bytes versus ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:metrics Issues and PRs related to the Metrics API feature-request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants