feat(statsd): Add sampling parameter to distribution metrics#5576
Merged
feat(statsd): Add sampling parameter to distribution metrics#5576
Conversation
…er metrics
The `metric!(distribution(...))` and `metric!(timer(...))` macros now support
an optional `sampling` parameter to explicitly set a per-metric sampling rate
that overrides the global sample rate.
Example usage:
```rust
// Uses global sample rate (default behavior, unchanged)
metric!(distribution(MyMetric) = value);
metric!(timer(MyTimer) = duration);
// Override with explicit sample rate
metric!(distribution(MyMetric, sampling = 0.01) = value);
metric!(timer(MyTimer, sampling = 0.01) = duration);
metric!(timer(MyTimer, sampling = 0.01), { block });
```
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
8581a4f to
24862d6
Compare
This reverts commit 07b5003.
jjbayer
commented
Jan 23, 2026
relay-statsd/src/lib.rs
Outdated
| pub fn send_metric_with_sample_rate<'a, T>( | ||
| &'a self, | ||
| mut metric: MetricBuilder<'a, '_, T>, | ||
| sample_rate: Option<f64>, |
Member
Author
There was a problem hiding this comment.
Unfortunately we cannot inspect MetricBuilder to check whether a sample rate was set, so we have to pass it explicitly.
jjbayer
commented
Jan 23, 2026
| Self::InMemory(buffer) => buffer.push(envelope).await, | ||
| }?; | ||
| relay_statsd::metric!( | ||
| distribution(RelayDistributions::BufferEnvelopeBodySize, sample = 0.01) = |
Member
Author
There was a problem hiding this comment.
I reverted the temporary change of #5571 and set a sample rate instead.
Dav1dde
approved these changes
Jan 23, 2026
relay-statsd/src/lib.rs
Outdated
| pub fn send_metric_with_sample_rate<'a, T>( | ||
| &'a self, | ||
| mut metric: MetricBuilder<'a, '_, T>, | ||
| sample_rate: Option<f64>, |
Member
There was a problem hiding this comment.
Any specific reason you went with f64 over f32 which is used for the config?
Member
Author
There was a problem hiding this comment.
f64 is what cadence expects, that's all (self.sample_rate gets converted to f64 down below).
loewenheim
approved these changes
Jan 23, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
metric!(distribution(...))andmetric!(timer(...))macros now take an optionalsampleparameter to explicitly set the sampling rate the metric. This allows per-metric control over sampling rates via cadence'swith_sampling_rate.Example usage:
ref: INGEST-659