Skip to content

feat: Allow specifying aggregation for SynchronousInstruments #1837

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joshwestbrook
Copy link
Contributor

Our application has a handful of legacy API endpoints that far exceed the default explicit histogram buckets, and currently there is no way to override the default buckets for histograms. Allowing the aggregation to be explicitly provided for SyncrhonousInstruments means we will be able to get data that is actually representative of our API response times.

@joshwestbrook joshwestbrook force-pushed the specify-instrument-aggregation branch 2 times, most recently from 8949ea4 to 3f18d42 Compare April 23, 2025 16:19
@joshwestbrook joshwestbrook marked this pull request as ready for review April 25, 2025 14:35
@joshwestbrook joshwestbrook force-pushed the specify-instrument-aggregation branch from 3f18d42 to b535565 Compare May 2, 2025 14:21
@kaylareopelle
Copy link
Contributor

Hi @joshwestbrook, thanks for this PR and for your patience!

If I'm understanding your situation, I think the add_view method might suit your needs.

In this example below, a view is added to the http.server.request.duration metric to override the default boundaries by creating a new ExplicitBucketHistogram with the desired boundaries passed as an arg:

OpenTelemetry.meter_provider.add_view(
  'http.server.request.duration', 
   aggregation: 
     OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.new(
       boundaries: [
         0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10
       ]
     )
   )

histogram = APP_METER.create_histogram(
  'http.server.request.duration', 
  unit: 's', 
  description: 'Duration of HTTP server requests.'
)

Could you give this a try?

Here's more documentation on Metric Views in OpenTelemetry.

@joshwestbrook
Copy link
Contributor Author

Hey Kayla! I appreciate the suggestion, I didn't realize views were ready to be used yet! I'll give that a shot and follow back up with you 😄

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

Successfully merging this pull request may close these issues.

2 participants