Content-Length: 391050 | pFad | http://github.com/getsentry/sentry-javascript/pull/15569

AE feat(browser): Add `previous_trace` span links by Lms24 · Pull Request #15569 · getsentry/sentry-javascript · GitHub
Skip to content
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

feat(browser): Add previous_trace span links #15569

Merged
merged 15 commits into from
Mar 21, 2025
Merged

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Mar 4, 2025

This PR adds logic to set the previous_trace span link on root spans (via browserTracingIntegration).

Some notes:

  • added linkPreviousTrace integration option to control the trace linking behaviour:
    • in-memory - default - previous trace data is linked and stored in memory
    • session-storage - previous trace data is linked and stored in session storage
    • off - no previous trace data is stored or linked
  • we can't yet sample on the previous trace in tracesSampler but this I'll tackle via Add possibility to sample subsequent traces based on previous trace sampling decision #15754
  • everything is implemented within browserTracingIntegration, meaning there's no bundle size hit for error-only users or users who only send manual spans (the latter is a tradeoff but I think it's a fair one)
  • added unit and integration tests for a bunch of scenarios

Happy to bike shed on the options naming :D

closes #14992

UPDATE: I rewrote the public API options from having two options (enablePreviousTrace and persistPreviousTrace) to only one which controls both aspects.

Copy link
Contributor

github-actions bot commented Mar 4, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.28 KB - -
@sentry/browser - with treeshaking flags 23.09 KB - -
@sentry/browser (incl. Tracing) 36.6 KB +0.78% +287 B 🔺
@sentry/browser (incl. Tracing, Replay) 73.79 KB +0.41% +305 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.14 KB +0.34% +231 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 78.42 KB +0.39% +307 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 90.99 KB +0.37% +338 B 🔺
@sentry/browser (incl. Feedback) 40.41 KB - -
@sentry/browser (incl. sendFeedback) 27.91 KB - -
@sentry/browser (incl. FeedbackAsync) 32.71 KB - -
@sentry/react 25.07 KB - -
@sentry/react (incl. Tracing) 38.53 KB +0.76% +296 B 🔺
@sentry/vue 27.5 KB - -
@sentry/vue (incl. Tracing) 38.3 KB +0.74% +288 B 🔺
@sentry/svelte 23.31 KB - -
CDN Bundle 24.5 KB - -
CDN Bundle (incl. Tracing) 36.61 KB +0.67% +248 B 🔺
CDN Bundle (incl. Tracing, Replay) 71.62 KB +0.33% +235 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 76.82 KB +0.31% +236 B 🔺
CDN Bundle - uncompressed 71.63 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.66 KB +0.62% +684 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.92 KB +0.31% +684 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 232.49 KB +0.29% +684 B 🔺
@sentry/nextjs (client) 39.81 KB +0.73% +295 B 🔺
@sentry/sveltekit (client) 37.03 KB +0.79% +294 B 🔺
@sentry/node 142.63 KB - -
@sentry/node - without tracing 96.01 KB - -
@sentry/aws-serverless 120.38 KB - -

View base workflow run

@Lms24 Lms24 self-assigned this Mar 4, 2025
@Lms24 Lms24 force-pushed the lms/feat-previous-trace-links branch from 66ec822 to 45bc790 Compare March 19, 2025 15:40
@Lms24 Lms24 marked this pull request as ready for review March 20, 2025 11:51
@Lms24 Lms24 requested review from s1gr1d and mydea March 20, 2025 11:51
Comment on lines 396 to 400
previousTraceInfo = addPreviousTraceSpanLink(previousTraceInfo, span);

if (persistPreviousTrace) {
storePreviousTraceInSessionStorage(previousTraceInfo);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think all this code around the previous trace can be put in here. Then there is also no need to mutate the variable or store undefined in a variable if persisting is turned off.

Suggested change
previousTraceInfo = addPreviousTraceSpanLink(previousTraceInfo, span);
if (persistPreviousTrace) {
storePreviousTraceInSessionStorage(previousTraceInfo);
}
if (persistPreviousTrace) {
const updatedPreviousTraceInfo = addPreviousTraceSpanLink(
getPreviousTraceFromSessionStorage(), span
)
storePreviousTraceInSessionStorage(updatedPreviousTraceInfo);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to rewrite this but I still need to call addPreviousTraceSpanLink if persistPreviousTrace is false (as by default). Let me take another look

Copy link
Member Author

Choose a reason for hiding this comment

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

I rewrote this a bit based on your suggestion as well as on unifying the two options. b44e790

@Lms24 Lms24 force-pushed the lms/feat-previous-trace-links branch from 0550ac6 to 6c42afd Compare March 20, 2025 14:25
@Lms24 Lms24 requested a review from s1gr1d March 21, 2025 09:56
Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Such nice API 🥇

@Lms24 Lms24 merged commit 1a4fa0c into develop Mar 21, 2025
153 checks passed
@Lms24 Lms24 deleted the lms/feat-previous-trace-links branch March 21, 2025 10:21
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.

Add previous_trace span link to browserTracingIntegration root spans
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/getsentry/sentry-javascript/pull/15569

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy