Skip to content

ref(server-utils): Move server-only utils out of core - #23826

Draft
mydea wants to merge 1 commit into
developfrom
fn/move-server-only-apis-to-server-utils
Draft

ref(server-utils): Move server-only utils out of core#23826
mydea wants to merge 1 commit into
developfrom
fn/move-server-only-apis-to-server-utils

Conversation

@mydea

@mydea mydea commented Sep 1, 2026

Copy link
Copy Markdown
Member

Continues slimming @sentry/core toward the isomorphic surface by moving a batch of server-only helpers out of @sentry/core/server into @sentry/server-utils (following the same pattern as the browser span-API move).

Moved to @sentry/server-utils:

  • flushIfServerless + vercelWaitUntil
  • trpcMiddleware
  • callFrameToStackFrame / watchdogTimer (anr worker helpers)
  • loadModule (split out of utils/node)

Why these are safe to move: each only depended on the public @sentry/core API (anr additionally uses filenameIsInApp from @sentry/core/server, which stays), so nothing in core's public surface had to be expanded. Every consumer already depends on @sentry/server-utils, so this only changes the internal import path — the public SDK packages (@sentry/node, @sentry/nextjs, …) keep re-exporting these under the same names, so there is no user-facing change.

Decisions:

  • isNodeEnv stays in @sentry/core: core itself depends on it (via isBrowser), so it cannot move without a cycle. loadModule was split out of the same utils/node file.
  • mcp-server and the integrations/http/* subtree are deliberately left in core. Unlike the helpers above, they import several non-public core internals (getSpanName, resolveDataCollectionOptions, getBreadcrumbLogLevel, getDefaultExport, generatePropagationContext, and the internal client/scope modules). Moving them would require promoting those internals to core's public API, which is a separate call to make.
  • Tests for the moved modules were relocated into @sentry/server-utils and rewritten to spy on the public @sentry/core namespace; consumer test mocks were retargeted from @sentry/core/server to @sentry/server-utils (using light full-replacement mocks rather than importOriginal, to avoid force-loading the whole server-utils integration graph).

Moves a batch of server-only helpers out of `@sentry/core/server` into
`@sentry/server-utils`, continuing the effort to slim `@sentry/core` down to the
isomorphic surface. The moved symbols only ever depended on the public
`@sentry/core` API (plus the `@sentry/core/server` `filenameIsInApp` for anr), so
they relocate cleanly without expanding core's public surface.

Moved:
- `flushIfServerless` + `vercelWaitUntil` (used by the meta-framework SDKs)
- `trpcMiddleware`
- `callFrameToStackFrame` / `watchdogTimer` (the anr worker helpers)
- `loadModule` (split out of `utils/node`, `isNodeEnv` stays in core since core
  itself depends on it via `isBrowser`)

Every consumer already depends on `@sentry/server-utils`, so this only changes
the internal import path; the public SDK packages keep re-exporting these under
the same names, so there is no user-facing change.

`mcp-server` and the `integrations/http/*` subtree are intentionally left in core
for now: unlike the above, they import a number of non-public core internals
(`getSpanName`, `resolveDataCollectionOptions`, `getBreadcrumbLogLevel`,
`getDefaultExport`, `generatePropagationContext`, the internal `client`/`scope`
modules), so moving them would require promoting those to core's public API — a
separate decision.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 172fba6. Configure here.

export type { ServerRuntimeOptions } from './types/options';
export { trpcMiddleware } from './trpc';
export { wrapMcpServerWithSentry } from './integrations/mcp-server';
export { isNodeEnv, loadModule } from './utils/node';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Leftover import of removed export

Medium Severity

flushIfServerless was removed from @sentry/core/server, but the nuxt-3 e2e app still imports it from that path. That application will fail to start, so the e2e suite that exercises the custom Nitro error handler no longer runs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 172fba6. Configure here.

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.

1 participant