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)!: Update requestDataIntegration handling #14806

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 19, 2024

This PR cleans up the behavior of requestDataIntegration. For this, there are a bunch of parts that come together:

  1. Removed the addNormalizedRequestDataToEvent export, this does not really do much, you can just directly add the data to the event.
  2. Removed the RequestDataIntegrationOptions type
  3. Stops setting request on SDK processing metadata, now only relying on normalizedRequest
  4. Streamlined code related to this, taking it out of utils-hoist. Now, all the code related directly to the requestDataIntegration is in that file, while the more general utils are in core/src/utils/request.ts
  5. Also moved the cookie & getClientIpAddress utils out of utils-hoist
  6. Added tests for the request utils, we did not have any unit tests there...
  7. Streamlined the header extraction to avoid debug logs and simply try-catch there normally
  8. Streamlined the request extraction to avoid weird urls if no host is found.

Closes #14297

@mydea mydea self-assigned this Dec 19, 2024
Copy link
Contributor

github-actions bot commented Dec 19, 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 23.01 KB - -
@sentry/browser - with treeshaking flags 21.68 KB - -
@sentry/browser (incl. Tracing) 35.53 KB - -
@sentry/browser (incl. Tracing, Replay) 72.31 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.83 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.57 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.59 KB - -
@sentry/browser (incl. Feedback) 39.23 KB - -
@sentry/browser (incl. sendFeedback) 27.64 KB - -
@sentry/browser (incl. FeedbackAsync) 32.41 KB - -
@sentry/react 25.71 KB - -
@sentry/react (incl. Tracing) 38.31 KB - -
@sentry/vue 27.12 KB - -
@sentry/vue (incl. Tracing) 37.27 KB - -
@sentry/svelte 23.13 KB - -
CDN Bundle 24.28 KB - -
CDN Bundle (incl. Tracing) 35.82 KB - -
CDN Bundle (incl. Tracing, Replay) 70.47 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 75.62 KB - -
CDN Bundle - uncompressed 70.78 KB - -
CDN Bundle (incl. Tracing) - uncompressed 106.08 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 216.91 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.44 KB - -
@sentry/nextjs (client) 38.42 KB - -
@sentry/sveltekit (client) 36.08 KB - -
@sentry/node 161.46 KB -0.16% -260 B 🔽
@sentry/node - without tracing 97.24 KB -0.25% -240 B 🔽
@sentry/aws-serverless 127.11 KB -0.2% -250 B 🔽

View base workflow run

mydea added a commit that referenced this pull request Dec 30, 2024
Fixes #14847

After some digging, I figured out that the `req.user` handling on
express is not working anymore, because apparently express does not
mutate the actual http `request` object, but clones/forkes it (??)
somehow. So since we now set the request in the
SentryHttpInstrumentation generally, it would not pick up
express-specific things anymore.

IMHO this is not great and we do not want this anymore in v9 anyhow, but
it was the behavior before. This PR fixes this by setting the express
request again on the isolation scope in an express middleware, which is
registered by `Sentry.setupExpressErrorHandler(app)`.

Note that we plan to change this behavior here:
#14806 but I figured
it still makes sense to fix this on develop first, so we have a proper
history/tests for this. I will backport this to v8 too. Then, in PR
#14806 I will remove the middleware again.
mydea added a commit that referenced this pull request Jan 3, 2025
Instead of picking this from the plain `request` in `requestDartaIntegration`.

Extracted from #14806
mydea added a commit that referenced this pull request Jan 7, 2025
Instead of picking this from the plain `request` in
`requestDartaIntegration`.

Extracted from #14806
mydea added a commit that referenced this pull request Jan 7, 2025
This was an express-specific, rather undocumented behavior, and also
conflicted with our privacy-by-default stance.

Starting in v9, you'll need to manually call `Sentry.setUser()` e.g. in
a middleware to set the user on Sentry events.

Docs for this are already pending:
getsentry/sentry-docs#12224

Extracted this out of
#14806
@mydea mydea force-pushed the fn/normalized-request branch from 4f9f9f7 to 72f6880 Compare January 8, 2025 15:30
@mydea mydea changed the title feat: Update requestDataIntegration handling feat(core)!: Update requestDataIntegration handling Jan 8, 2025
}
});
} catch {
// just return the empty headers
Copy link
Member Author

Choose a reason for hiding this comment

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

we used to log a debug message here, no we just continue.

}
});
} catch {
// just return the empty headers
Copy link
Member Author

Choose a reason for hiding this comment

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

we used to log a debug message here, no we just continue.

const protocol = request.protocol || (request.socket?.encrypted ? 'https' : 'http');
const url = request.url || '';

const absoluteUrl = getAbsoluteUrl({
Copy link
Member Author

Choose a reason for hiding this comment

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

previously, we always built this from the host. However, the host could also be <no host> as fallback, leading to (theoretically) urls like: http://<no host>/ which is weird. Now, we simply have no URL in such a case.

protocol,
host,
}: { url?: string; protocol: string; host?: string }): string | undefined {
if (url && url.startsWith('http')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

previously, we checked here url.startsWith(protocol). Which should be generally fine, but there could be an edge case where you have url: http://example.com and protocol: https which would result in https://http://example.com which seems bad.

packages/core/src/integrations/requestdata.ts Outdated Show resolved Hide resolved
@@ -60,7 +59,6 @@ export interface SdkProcessingMetadata {
requestSession?: {
status: 'ok' | 'errored' | 'crashed';
};
request?: PolymorphicRequest;
Copy link
Member

Choose a reason for hiding this comment

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

bless

@mydea mydea force-pushed the fn/normalized-request branch from fd5d6ab to 3d17c65 Compare January 10, 2025 11:34
@mydea mydea force-pushed the fn/normalized-request branch from 3d17c65 to 95fb966 Compare January 13, 2025 07:36
@mydea mydea merged commit 46ac778 into develop Jan 13, 2025
156 checks passed
@mydea mydea deleted the fn/normalized-request branch January 13, 2025 07:55
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.

[v9] Remove non-normalized request handling in requestDataIntegration
3 participants