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(core): Ensure normalizedRequest on sdkProcessingMetadata is merged #14315

Merged
merged 10 commits into from
Nov 19, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Nov 15, 2024

We keep normalizedRequest with data like headers, urls etc. on the sdkProcessingMetadata on the scope.

While this generally works, there are some potential pitfalls/footguns there:

One, if you put some (e.g. partial) normalizedRequest on the current scope, it will just overwrite the full normalizedRequest from the isolation scope, where generally we'll try to put the request data automatically (e.g. in the http instrumentation). Think this example:

Sentry.withScope(scope => {
  scope.setSdkProcessingMetadata({ normalizedRequest: { headers: moreSpecificHeaders } });
});

the resulting event inside of this withScope callback would only have the headers, but would miss e.g. url etc. data set.

This PR changes this so that the normalizedRequest is merged between the types of scopes, so only set fields on e.g. the current scope will overwrite the same fields on the isolation scope, instead of just overwriting the whole normalizedRequest that results.

Note that bundle size for browser is sadly anyhow affected (no matter if we go with a/b/c), as the code to merge it between scopes is always shared :(

@mydea mydea self-assigned this Nov 15, 2024
Copy link
Contributor

github-actions bot commented Nov 15, 2024

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 22.8 KB +0.15% +33 B 🔺
@sentry/browser - with treeshaking flags 21.57 KB +0.18% +38 B 🔺
@sentry/browser (incl. Tracing) 35.31 KB +0.13% +44 B 🔺
@sentry/browser (incl. Tracing, Replay) 72.06 KB +0.08% +53 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.43 KB +0.08% +47 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.35 KB +0.06% +42 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 89.19 KB +0.03% +24 B 🔺
@sentry/browser (incl. Feedback) 39.96 KB +0.08% +32 B 🔺
@sentry/browser (incl. sendFeedback) 27.45 KB +0.13% +34 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.27 KB +0.15% +47 B 🔺
@sentry/react 25.58 KB +0.2% +52 B 🔺
@sentry/react (incl. Tracing) 38.26 KB +0.09% +32 B 🔺
@sentry/vue 26.95 KB +0.12% +33 B 🔺
@sentry/vue (incl. Tracing) 37.14 KB +0.11% +40 B 🔺
@sentry/svelte 22.94 KB +0.15% +35 B 🔺
CDN Bundle 24.16 KB +0.13% +31 B 🔺
CDN Bundle (incl. Tracing) 37.11 KB +0.16% +60 B 🔺
CDN Bundle (incl. Tracing, Replay) 71.78 KB +0.08% +57 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.12 KB +0.07% +50 B 🔺
CDN Bundle - uncompressed 70.86 KB +0.19% +135 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 110.07 KB +0.12% +135 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 222.59 KB +0.06% +135 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 235.81 KB +0.06% +135 B 🔺
@sentry/nextjs (client) 38.37 KB +0.05% +19 B 🔺
@sentry/sveltekit (client) 35.88 KB +0.08% +28 B 🔺
@sentry/node 134.4 KB +0.06% +75 B 🔺
@sentry/node - without tracing 96.25 KB +0.05% +47 B 🔺
@sentry/aws-serverless 106.54 KB +0.06% +56 B 🔺

View base workflow run

Copy link

codecov bot commented Nov 15, 2024

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
654 2 652 24
View the top 2 failed tests by shortest run time
transactions.test.ts Captures request metadata
Stack Traces | 0.035s run time
transactions.test.ts:139:5 Captures request metadata
errors.test.ts Sends graphql exception to Sentry
Stack Traces | 0.054s run time
errors.test.ts:73:5 Sends graphql exception to Sentry

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

@mydea mydea changed the title fix(core): Ensure normalizedRequest on sdkProcessingMetadata is merged feat(core): Ensure normalizedRequest on sdkProcessingMetadata is merged Nov 15, 2024
@mydea mydea marked this pull request as ready for review November 15, 2024 09:37
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Sounds good to me!

@mydea mydea force-pushed the fn/normalizedRequestMerge branch 2 times, most recently from a56fc65 to 4705e11 Compare November 18, 2024 09:12
@@ -95,6 +95,13 @@ describe('createSpanEnvelope', () => {
client = new TestClient(options);
setCurrentClient(client);
client.init();

// We want to avoid console errors in the tests
jest.spyOn(console, 'error').mockImplementation(() => {});
Copy link
Member Author

Choose a reason for hiding this comment

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

Finally added this because it kept annoying me when running these tests locally to get this test log output all the time 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I'll move this out to #14358

@mydea mydea merged commit e75bcb8 into develop Nov 19, 2024
149 of 151 checks passed
@mydea mydea deleted the fn/normalizedRequestMerge branch November 19, 2024 15:30
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