Skip to content

Conversation

@k-fish
Copy link
Member

@k-fish k-fish commented Nov 5, 2025

This allows for a sample_rate (0, 1.0] to be sent on a per metric basis.

Refs LOGS-497

This allows for a sample_rate (0, 1.0] to be sent on a per metric basis.

Refs LOGS-497
@linear
Copy link

linear bot commented Nov 5, 2025

@k-fish k-fish requested a review from chargome November 5, 2025 22:10
@k-fish k-fish force-pushed the feat/tracemetrics/add-sample-rate-function branch from 393fb60 to 1d11dca Compare November 5, 2025 22:16
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.64 kB - -
@sentry/browser - with treeshaking flags 23.13 kB - -
@sentry/browser (incl. Tracing) 41.26 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.54 kB - -
@sentry/browser (incl. Tracing, Replay) 79.74 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.43 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.44 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.61 kB - -
@sentry/browser (incl. Feedback) 41.31 kB - -
@sentry/browser (incl. sendFeedback) 29.31 kB - -
@sentry/browser (incl. FeedbackAsync) 34.24 kB - -
@sentry/react 26.32 kB - -
@sentry/react (incl. Tracing) 43.24 kB - -
@sentry/vue 29.13 kB - -
@sentry/vue (incl. Tracing) 43.05 kB - -
@sentry/svelte 24.65 kB - -
CDN Bundle 27.06 kB +0.6% +160 B 🔺
⛔️ CDN Bundle (incl. Tracing) (max: 42 kB) 42 kB +0.5% +205 B 🔺
CDN Bundle (incl. Tracing, Replay) 78.53 kB +0.27% +210 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 83.99 kB +0.23% +190 B 🔺
CDN Bundle - uncompressed 79.56 kB +0.85% +664 B 🔺
⛔️ CDN Bundle (incl. Tracing) - uncompressed (max: 124.1 kB) 124.67 kB +0.54% +664 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 240.71 kB +0.28% +664 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 253.47 kB +0.27% +664 B 🔺
@sentry/nextjs (client) 45.36 kB - -
@sentry/sveltekit (client) 41.67 kB - -
@sentry/node-core 50.81 kB - -
@sentry/node 157.88 kB -0.01% -1 B 🔽
@sentry/node - without tracing 92.69 kB - -
@sentry/aws-serverless 106.42 kB - -

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,898 - 8,887 +0%
GET With Sentry 1,351 15% 1,427 -5%
GET With Sentry (error only) 6,191 70% 6,176 +0%
POST Baseline 1,206 - 1,195 +1%
POST With Sentry 506 42% 506 -
POST With Sentry (error only) 1,053 87% 1,068 -1%
MYSQL Baseline 3,260 - 3,336 -2%
MYSQL With Sentry 464 14% 580 -20%
MYSQL With Sentry (error only) 2,712 83% 2,720 -0%

View base workflow run

if (metric.sample_rate <= 0 || metric.sample_rate > 1.0) {
client.recordDroppedEvent('invalid_sample_rate', 'metric');
return false;
}
Copy link

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.

Fix in Cursor Fix in Web

setMetricAttribute(processedMetricAttributes, 'sentry._internal.replay_is_buffering', true);
const { sampled, samplingPerformed } = shouldSampleMetric(beforeMetric, currentScope);
if (!sampled) {
return;
Copy link

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.

Fix in Cursor Fix in Web

@timfish
Copy link
Collaborator

timfish commented Nov 6, 2025

Strange how this has impacted the CDN Bundles but nothing else 🤔

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.

3 participants