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

ref(node): Move request-data-extraction functions to@sentry/utils #5257

Merged
merged 7 commits into from
Jun 15, 2022

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Jun 13, 2022

See #5190 for a detailed description of the motivation for and main substance of this change. TL;DR, isomorphic frameworks like Nextjs need this code to live in a neutral location (rather than in the node package) so it can be used in a browser setting as well.

This is a second take on #5190, which had to be reverted because it relied on a peer dependency (cookie) which browser-only apps wouldn't have installed. Even if those code didn't use cookie, they still failed to compile because without cookie installed, @sentry/utils didn't typecheck correctly.

This fixes that problem by using cookie (and url, for node 8 compatibility) only as injected dependencies, not as direct ones. It also creates node-specific versions of the relevant functions (parseRequest, now renamed addRequestDataToEvent, and extractRequestData) which do the injection automatically. If the dependencies aren't passed (as would be the case in a browser setting, or when using the functions directly from @sentry/utils), the code about cookies no-ops, and the code about URLs uses URL, which should be defined in all modern browsers and Node 10 and above.

Other changes from the original PR:

  • Now only the backwards-compatibility-preserving wrappers of the legacy code live in handlers.ts, while the legacy code itself lives in its own file. This both makes it easier to delete in the future and ensures that treeshaking algorithms which only work file-by-file (rather than function-by-function) are able to exclude that code. (Though it's being kept until v8 because it's part of the node package's public API, it's no longer used anywhere in the SDK.)
  • Using DI changed the options interface for both of the functions in question, which in turn required a bit more gymnastics in terms of preserving and test backwards compatibility, specifically in the serverless package and the backwards-compatibility tests. This will make it a little harder to delete the old stuff when it comes time, but there are TODOs which hopefully will make it clear enough what needs to happen.
  • There's a new CrossPlatformRequest type for use in place of ExpressRequest. A few helper functions have also been renamed to make them less Express-centric.

Ref: WEB-957

@lobsterkatie lobsterkatie force-pushed the kmclb-move-requestdata-fns-to-utils branch from a58d622 to e8774f2 Compare June 13, 2022 18:52
@github-actions
Copy link
Contributor

github-actions bot commented Jun 13, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.43 KB (added)
@sentry/browser - ES5 CDN Bundle (minified) 60.21 KB (added)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.24 KB (added)
@sentry/browser - ES6 CDN Bundle (minified) 53.83 KB (added)
@sentry/browser - Webpack (gzipped + minified) 20 KB (added)
@sentry/browser - Webpack (minified) 65.2 KB (added)
@sentry/react - Webpack (gzipped + minified) 20.02 KB (added)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.02 KB (added)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.63 KB (added)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.16 KB (added)

@lobsterkatie lobsterkatie force-pushed the kmclb-move-requestdata-fns-to-utils branch 2 times, most recently from 239ee22 to ee1316e Compare June 13, 2022 19:01
packages/node/src/client.ts Outdated Show resolved Hide resolved
packages/utils/src/requestdata.ts Show resolved Hide resolved
packages/node/test/requestdata.test.ts Show resolved Hide resolved
@lobsterkatie lobsterkatie force-pushed the kmclb-move-requestdata-fns-to-utils branch 2 times, most recently from a6249e0 to 230c07d Compare June 15, 2022 03:17
@lobsterkatie lobsterkatie merged commit d69cafc into master Jun 15, 2022
@lobsterkatie lobsterkatie deleted the kmclb-move-requestdata-fns-to-utils branch June 15, 2022 14:39
AbhiPrasad pushed a commit that referenced this pull request Jun 22, 2022
#5287)

This fixes an issue introduced by #5257, which was designed to be  backwards-compatible, but which missed a key use case: When users pass options to our Express middleware, they might be (and in fact, for now, almost certainly are) passing them in the form of `ParseRequestOptions`, not `AddRequestDataToEventOptions`. This allows for that possibility, as a backwards-compatibility measure until v8. It also adjusts a spot in the serverless SDK where a similar problem can occur.

Fixes #5282.
@mydea mydea mentioned this pull request Nov 9, 2023
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.

2 participants