-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracemetrics): Add sample_rate parameter to metric API calls #18103
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
base: develop
Are you sure you want to change the base?
Conversation
This allows for a sample_rate (0, 1.0] to be sent on a per metric basis. Refs LOGS-497
393fb60 to
1d11dca
Compare
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
| if (metric.sample_rate <= 0 || metric.sample_rate > 1.0) { | ||
| client.recordDroppedEvent('invalid_sample_rate', 'metric'); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Invalid NaN Rejection in Sample Rate Validation
The sample_rate validation doesn't properly reject NaN values. When sample_rate is NaN, the condition metric.sample_rate <= 0 || metric.sample_rate > 1.0 evaluates to false (since all comparisons with NaN return false), allowing NaN to pass validation. This causes the metric to be silently dropped during sampling (since sampleRand < NaN is always false) without recording a dropped event. The validation should explicitly check for NaN and reject it as invalid.
| setMetricAttribute(processedMetricAttributes, 'sentry._internal.replay_is_buffering', true); | ||
| const { sampled, samplingPerformed } = shouldSampleMetric(beforeMetric, currentScope); | ||
| if (!sampled) { | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missed Tracking of Sampled-Out Metrics Drops
When a metric is dropped due to sampling (when sampled is false), the code does not record this as a dropped event using client.recordDroppedEvent('sample_rate', 'metric'). The EventDropReason type already includes 'sample_rate' as a valid drop reason, and the code properly records drops for invalid sample rates at line 90, but fails to record drops for valid sampling decisions. This means sampled-out metrics won't be tracked in client reports, making it impossible to monitor how many metrics are being dropped due to sampling.
|
Strange how this has impacted the CDN Bundles but nothing else 🤔 |
This allows for a sample_rate (0, 1.0] to be sent on a per metric basis.
Refs LOGS-497