Skip to content

Conversation

PoorlyDefinedBehaviour
Copy link
Contributor

  • Adds a view to theSdkMeterProvider
  • Functions that create exponential histograms add their names to a map
  • For each instrument, the view checks if the instrument is a member of the exponential histograms map, and if it is, changes the instrument's aggregation to Aggregation::Base2ExponentialHistogram

The feature spec_unstable_metrics_views is required to use the view functionality.

Comment on lines 14 to 32
($method: ident, $ty:ty, $var_name:literal, $usage:literal) => {
($method: ident, $ty:ty, $var_name:literal, $usage:literal, $show_header: ident) => {
concat!(
"Wrapper for [`Meter::", stringify!($method), "`] using Pydantic Logfire's global meter.
metric_doc_header!($show_header, $method),
"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have an alternative header for the exponential histograms, which explains what they are, given there isn't an upstream doc to link to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Will add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

src/metrics.rs Outdated
Comment on lines 138 to 143
let mut histograms = EXPONENTIAL_HISTOGRAMS
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let name = name.into();
histograms.insert(name.clone(), scale);
u64_histogram(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we potentially wrap the return value as a struct ExponentialHistogram so that on drop it can remove the name from the global? Might be cleaner.

Copy link
Contributor Author

@PoorlyDefinedBehaviour PoorlyDefinedBehaviour Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also remove from the map after the histogram is passed to the view function. I'm not completely sure that removing from the map is safe since the spec doesn't say how many times the view function will be called for each metric.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I think if we clean up we should do it when the whole instrument is dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented Drop to clean up

src/metrics.rs Outdated
.unwrap_or_else(std::sync::PoisonError::into_inner);
let name = name.into();
histograms.insert(name.clone(), scale);
f64_histogram(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the base2 aggregation affect the bucketing going on here? Should this use a different underlying instrument to avoid any bucketing here being a problem?

@adriangb
Copy link
Member

@PoorlyDefinedBehaviour let's get CI green then we can merge this. We'll test it in our codebase and see what the data looks like once it's exported, etc. Sound good?

@PoorlyDefinedBehaviour
Copy link
Contributor Author

@PoorlyDefinedBehaviour let's get CI green then we can merge this. We'll test it in our codebase and see what the data looks like once it's exported, etc. Sound good?

Sounds good, hadn't seen this comment

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 93.16770% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/metrics.rs 90.90% 8 Missing ⚠️
src/logfire.rs 95.71% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let's ship this and see how it looks👍

@davidhewitt davidhewitt merged commit a1e553a into main Aug 21, 2025
7 checks passed
@davidhewitt davidhewitt deleted the add-exponential-histograms-support branch August 21, 2025 08:34
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.

4 participants