feat(core): split exports by browser/server for bundle size#20435
feat(core): split exports by browser/server for bundle size#20435
Conversation
143a2a5 to
1494709
Compare
size-limit report 📦
|
d5dddbf to
8eba1e9
Compare
8eba1e9 to
8ea4f5c
Compare
8ea4f5c to
787f44b
Compare
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs, in `@sentry/core` where they can be easily shared across runtimes. Integration may require updating our `tsconfig` settings so that tsc knows it is allowed to look on `package.json` exports. fix: #20434 fix: JS-2243
787f44b to
7076f7c
Compare
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs, in `@sentry/core` where they can be easily shared across runtimes. Integration may require updating our `tsconfig` settings so that tsc knows it is allowed to look on `package.json` exports. fix: #20434 fix: JS-2243
7076f7c to
e2cf052
Compare
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs, in `@sentry/core` where they can be easily shared across runtimes. Integration may require updating our `tsconfig` settings so that tsc knows it is allowed to look on `package.json` exports. fix: #20434 fix: JS-2243
e2cf052 to
67bf5c4
Compare
timfish
left a comment
There was a problem hiding this comment.
I looked through most of the changed files.
I guess this doesn't deprecate the old root exports yet?
| expect.objectContaining({ | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'http.client', | ||
| 'sentry.origin': 'auto.http.otel.http', |
There was a problem hiding this comment.
these seem like unrelated changes, a different PR leaking into this? 😅
There was a problem hiding this comment.
Yes, this is based on #20393, but I think I'm going to reverse things and put this first, unless we can land that PR soon-ish.
| "include": ["src/**/*"], | ||
|
|
||
| "compilerOptions": { | ||
| "module": "esnext", |
There was a problem hiding this comment.
is this related to this change/required here?
| "include": ["src/**/*", "test/loader.js"], | ||
|
|
||
| "compilerOptions": { | ||
| "module": "esnext", |
There was a problem hiding this comment.
is this required for this change here?
|
|
||
| const getExpressExport = (express: ExpressModuleExport): ExpressExport => | ||
| hasDefaultProp(express) ? express.default : (express as ExpressExport); | ||
| import { getDefaultExport } from '../../utils/get-default-export'; |
There was a problem hiding this comment.
also likely leaked in from another PR?
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs in `@sentry/core`, where they can more easily be shared across runtimes. Some integration requires updating `tsconfig` settings so that tsc knows it is allowed to look up `package.json` exports. fix: #20434 fix: JS-2243
67bf5c4 to
2cf15db
Compare
This was implemented for the portable Express integration, but others will need the same functionality, so make it a reusable util.
Refactor the `node:http` outgoing request instrumentation so that it can be applied to non-Node.js environments by patching the http module. Also, refactor so that the diagnostics_channel and monkeypatching paths can share code, and so that light and normal node-core instrumentations can share more of the functionality as well. To facilitate this, some portable minimal types are vendored in from the `node:http` module.
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs in `@sentry/core`, where they can more easily be shared across runtimes. Some integration requires updating `tsconfig` settings so that tsc knows it is allowed to look up `package.json` exports. fix: #20434 fix: JS-2243
2cf15db to
c1c9cf0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c1c9cf0. Configure here.
| export const patchHttpsModuleClient = ( | ||
| httpModuleExport: HttpModuleExport, | ||
| options: HttpInstrumentationOptions = {}, | ||
| ): HttpModuleExport => patchModule(httpModuleExport, options); |
There was a problem hiding this comment.
Misleading docs and redundant identical exported functions
Low Severity
patchHttpsModuleClient is documented as setting "default protocol/port for HTTPS when option objects are passed," but its implementation is byte-for-byte identical to patchHttpModuleClient — both just call patchModule(httpModuleExport, options). The JSDoc promises behavior that doesn't exist. Having two identical exported functions with different names and misleading documentation adds unnecessary confusion. This was flagged because it was mentioned in this rules file (redundant code check).
Additional Locations (1)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit c1c9cf0. Configure here.
| const baseFn = toFilterFunction(base); | ||
| const specificFn = toFilterFunction(specific); | ||
| return id => baseFn(id) || specificFn(id); | ||
| } |
There was a problem hiding this comment.
mergeExternals drops Rollup's extra function arguments
Low Severity
mergeExternals returns id => baseFn(id) || specificFn(id), which only forwards the first argument (id) to the underlying functions. Rollup calls external with (id, parentId, isResolved). If any package-specific config provides an external function that uses parentId or isResolved, those arguments are silently dropped. The merged function could instead forward all arguments with a rest parameter.
Reviewed by Cursor Bugbot for commit c1c9cf0. Configure here.
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs in `@sentry/core`, where they can more easily be shared across runtimes. Some integration requires updating `tsconfig` settings so that tsc knows it is allowed to look up `package.json` exports. fix: #20434 fix: JS-2243
c1c9cf0 to
5beb2e3
Compare


Note: stacked atop #20393, only the top commit needs review. Land that before this one.
Split the exports from
@sentry/coreinto three options:@sentry/core, the default (unchanged)@sentry/core/browser, containing only shared and browser-specificfunctionality, nothing server-specific.
@sentry/core/server, containing only shared and server-specificfunctionality, nothing browser-specific.
This allows us to make the bundle sizes quite a bit smaller in our
browser SDKs where this is important, while adding more functionality to
our server-specific SDKs, in
@sentry/corewhere they can be easilyshared across runtimes.
fix: #20434
fix: JS-2243