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

Missing boundaries option in HistogramOptions #2999

Closed
fallenmanrisesup opened this issue May 30, 2022 · 5 comments
Closed

Missing boundaries option in HistogramOptions #2999

fallenmanrisesup opened this issue May 30, 2022 · 5 comments

Comments

@fallenmanrisesup
Copy link

fallenmanrisesup commented May 30, 2022

latest otel package versions, node 12

const { metrics, ValueType } = require("@opentelemetry/api-metrics");
// ...
const meter = metrics.getMeter(packageJSON.name, packageJSON.version);
const h1 = meter.createHistogram('test-metric', {
  boundaries: [0, 10, 100],
});
const h2 = meter.createHistogram('test-metric-2', {
  boundaries: [0, 5, 7, 9, 11, 13],
});

I tried to set up custom boundaries for buckets (I need exclusive for each instance, not for agregator), there is no boundaries option
in HistogramOptions .

@fallenmanrisesup fallenmanrisesup added the bug Something isn't working label May 30, 2022
@legendecas
Copy link
Member

legendecas commented May 30, 2022

This is by design. The boundaries now should be configured with Views. You can do it like

const { ExplicitBucketHistogramAggregation, InstrumentType } = require('@opentelemetry/sdk-metrics-sdk');
meterProvider.addView({
  aggregation: new ExplicitBucketHistogramAggregation([ /* custom boundaries */]);
}, {
  instrument: {
    type: InstrumentType.HISTOGRAM,
  },
});

// After the view is added, create the metric instrument
const h1 = meter.createHistogram('test-metric');

@legendecas legendecas removed the bug Something isn't working label May 30, 2022
@pichlermarc pichlermarc changed the title https://github.com/open-telemetry/opentelemetry-js/tree/ba3e3207edd217366710e10a769ba7ad4c4fa655/experimental/packages/opentelemetry-api-metrics Missing boundaries option in HistogramOptions May 30, 2022
@fallenmanrisesup
Copy link
Author

@legendecas It will give those boundaries for each histogram created by meter. I need to create N histogram metrics with it's own boundaries per metric

@vmarchaud
Copy link
Member

@legendecas
Copy link
Member

Closing as the question has been answered. Please feel to reopen if that is not the case.

@legendecas legendecas closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2022
@nwalters512
Copy link

nwalters512 commented Feb 16, 2023

I moved the below discussion to #3619.

Let me know if I should open a new issue for discussion, but this is really unergonomic in real-world code. While I recognize that it's neat to be able to take a single histogram and get multiple metrics out of it via Views, I'd consider the bucket boundaries to be an integral part of the histogram itself in most situations, and it would make a lot of sense to define the boundaries where the histogram itself is defined. Instead, I'd have to define these views where I initialize OTel, which is going to be in a completely unrelated part of my code. And AFAICT, there's no way to add or update views once a MeterProvider is instantiated.

This also means that there's no straightforward way share and reuse histogram metrics via libraries, as one can't ship the histogram buckets alongside the metric itself. This would be really useful for e.g. building a library that can capture common Node metrics, including a histogram for GC duration. I'm thinking about something akin to this from the Prometheus world: https://github.com/siimon/prom-client/blob/8d6456c05f0708fed34628da5bd6f492a0ab43f8/lib/metrics/gc.js.

Is there anything on the horizon that would make this easier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants