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): Attach virtual stack traces to HttpClient events. #14515

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Nov 27, 2024

Resolves: #8353

Updated fetch and xhr wrappers to pass virtual errors to the HttpClient integration so we can group the events with the stack traces.

It seems we can't create the virtual errors inside the HttpClient integration, as we're losing the non-Sentry frames.

Sampled fetch event - Link
Sampled XHR event - Link

Copy link
Contributor

github-actions bot commented Nov 27, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.11 KB +0.08% +18 B 🔺
@sentry/browser - with treeshaking flags 21.84 KB +0.04% +8 B 🔺
@sentry/browser (incl. Tracing) 35.51 KB +0.03% +10 B 🔺
@sentry/browser (incl. Tracing, Replay) 72.39 KB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.88 KB +0.02% +12 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.71 KB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 89.17 KB +0.01% +5 B 🔺
@sentry/browser (incl. Feedback) 39.84 KB +0.02% +6 B 🔺
@sentry/browser (incl. sendFeedback) 27.73 KB +0.05% +13 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.54 KB +0.04% +12 B 🔺
@sentry/react 25.8 KB +0.02% +5 B 🔺
@sentry/react (incl. Tracing) 38.41 KB +0.02% +5 B 🔺
@sentry/vue 27.26 KB +0.05% +13 B 🔺
@sentry/vue (incl. Tracing) 37.31 KB +0.03% +10 B 🔺
@sentry/svelte 23.26 KB +0.06% +12 B 🔺
CDN Bundle 24.33 KB +0.04% +8 B 🔺
CDN Bundle (incl. Tracing) 37.21 KB +0.04% +14 B 🔺
CDN Bundle (incl. Tracing, Replay) 72.1 KB +0.03% +18 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.43 KB +0.03% +20 B 🔺
CDN Bundle - uncompressed 71.48 KB +0.05% +35 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 110.54 KB +0.04% +35 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 223.61 KB +0.02% +35 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 236.83 KB +0.02% +35 B 🔺
@sentry/nextjs (client) 38.71 KB +0.01% +2 B 🔺
@sentry/sveltekit (client) 36.06 KB +0.03% +8 B 🔺
@sentry/node 135.08 KB - -
@sentry/node - without tracing 97.13 KB - -
@sentry/aws-serverless 109.43 KB - -

View base workflow run

@onurtemizkan onurtemizkan force-pushed the onur/httpclient-fingerprints branch 2 times, most recently from 252e544 to 7597e64 Compare November 27, 2024 18:43
Copy link

codecov bot commented Nov 27, 2024

❌ 29 Tests Failed:

Tests completed Failed Passed Skipped
661 29 632 27
View the top 3 failed tests by shortest run time
replay/extendNetworkBreadcrumbs/fetch/captureRequestBody/test.ts captures text request body
Stack Traces | 0.219s run time
test.ts:11:11 captures text request body
integrations/Breadcrumbs/fetch/statusCode/test.ts captures Breadcrumb with log level for 5xx response code
Stack Traces | 0.229s run time
test.ts:44:11 captures Breadcrumb with log level for 5xx response code
integrations/Breadcrumbs/fetch/get/test.ts captures Breadcrumb for basic GET request
Stack Traces | 0.236s run time
test.ts:7:11 captures Breadcrumb for basic GET request

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@onurtemizkan onurtemizkan force-pushed the onur/httpclient-fingerprints branch 3 times, most recently from ed1f24d to 21169f8 Compare November 27, 2024 20:04
@onurtemizkan onurtemizkan marked this pull request as ready for review November 27, 2024 20:04
@@ -75,6 +85,7 @@ export function instrumentXHR(): void {
endTimestamp: timestampInSeconds() * 1000,
startTimestamp,
xhr: xhrOpenThisArg,
error: httpClientInstrumented ? virtualError : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

m: Can we just directly attach the stackframe here, instead of passing the error around? then we can maybe just ignore these checks and simply always attach this here 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this made it work with ESM builds. Thanks!

Comment on lines 58 to 59
const virtualError = new Error();
const virtualStackTrace = virtualError.stack;
Copy link
Member

Choose a reason for hiding this comment

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

It is relatively expensive for engines to compute stack traces. I wonder if we could change this a bit so we don't create stack traces every time fetch is called but only when we actually need it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, passing a boolean whether the fetch/xhr instrumentations are triggered by HttpClient was flaky because of maybeInstrument, so passing the error itself in handler data under virtualError key (not to conflict with other integrations like Breadcrumbs that use error key) and creating the stacks inside HttpClient will hopefully give us a slight performance improvement. a7b89bc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants