Skip to content

feat(browser): Add option to sample linked traces consistently #16037

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

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Apr 11, 2025

This PR implements consistent sampling across traces as outlined in #15754. For a detailed write up see the issue.

Concrete changes:

  • Add sampleLinkedTracesConsistently option (naming TBD but this is what I'm going with for now)
  • Emit beforeSampling hook before sampling and creating SentrySpan's in the coreSDK (this hook is already called in Otel-based spans).
  • Allow beforeSampling hook subscribers to alter span attributes and parentSampled flag
  • Subscribe to beforeSampling hook when sampleLinkedTracesConsistently is enabled and linkPreviousTrace is not disabled
    • modify attributes and parentSampled flag based on the sampling decision, sample rate and sample rand of the previous trace
    • this will ensure that the newly started trace is sampled postitively/negatively depending on the decision of the previous trace
    • we also directly modify the propagation context to ensure that the previous trace's sampling decision, rate and rand are propagated correctly to downstream services and in the trace envelope header. This is necessary to ensure correct span metrics extrapolation.

@Lms24 Lms24 force-pushed the lms/feat-browser-sample-previous-trace branch from d9201af to 05e5a43 Compare April 11, 2025 15:28
@Lms24 Lms24 self-assigned this Apr 11, 2025
@Lms24 Lms24 requested a review from Copilot April 11, 2025 15:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Copy link
Contributor

github-actions bot commented Apr 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.3 KB +0.08% +18 B 🔺
@sentry/browser - with treeshaking flags 23.14 KB +0.09% +20 B 🔺
⛔️ @sentry/browser (incl. Tracing) (max: 37.11 KB) 37.15 KB +0.55% +206 B 🔺
⛔️ @sentry/browser (incl. Tracing, Replay) (max: 74.22 KB) 74.41 KB +0.37% +275 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.76 KB +0.38% +260 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 79.06 KB +0.33% +260 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 90.9 KB +0.32% +295 B 🔺
@sentry/browser (incl. Feedback) 39.68 KB +0.02% +7 B 🔺
@sentry/browser (incl. sendFeedback) 27.92 KB +0.09% +24 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.69 KB +0.06% +18 B 🔺
@sentry/react 25.11 KB +0.08% +19 B 🔺
@sentry/react (incl. Tracing) 39.08 KB +0.56% +220 B 🔺
@sentry/vue 27.57 KB +0.23% +63 B 🔺
@sentry/vue (incl. Tracing) 38.89 KB +0.59% +231 B 🔺
@sentry/svelte 23.33 KB +0.06% +12 B 🔺
CDN Bundle 24.53 KB +0.08% +18 B 🔺
CDN Bundle (incl. Tracing) 37.19 KB +0.66% +246 B 🔺
CDN Bundle (incl. Tracing, Replay) 72.25 KB +0.36% +263 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.4 KB +0.33% +253 B 🔺
CDN Bundle - uncompressed 71.52 KB +0.07% +46 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 109.93 KB +0.65% +722 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 221.22 KB +0.32% +722 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.76 KB +0.31% +722 B 🔺
@sentry/nextjs (client) 40.72 KB +0.57% +236 B 🔺
⛔️ @sentry/sveltekit (client) (max: 37.6 KB) 37.62 KB +0.62% +235 B 🔺
@sentry/node 143.25 KB +0.02% +22 B 🔺
@sentry/node - without tracing 96.5 KB +0.03% +27 B 🔺
@sentry/aws-serverless 120.79 KB +0.02% +20 B 🔺

View base workflow run

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.

1 participant