Skip to content

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

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

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).

Comment thread packages/core/src/server.ts
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>
@mydea
mydea force-pushed the fn/move-server-only-apis-to-server-utils branch from 172fba6 to d52ac53 Compare September 2, 2026 11:39

@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 d52ac53. Configure here.

} from '@sentry/core';
export { trpcMiddleware, wrapMcpServerWithSentry } from '@sentry/core/server';
export { wrapMcpServerWithSentry } from '@sentry/core/server';
export { trpcMiddleware } from '@sentry/server-utils';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Edge SDKs import Node-only barrel

Medium Severity

trpcMiddleware is re-exported from the main @sentry/server-utils entry, which evaluates Node-only modules such as node:diagnostics_channel and node:async_hooks. @sentry/vercel-edge already takes the rest of its server-utils imports from @sentry/server-utils/no-diagnostic-channels, which also re-exports trpcMiddleware. Importing the Node barrel from an edge entry can break bundling or startup in non-Node runtimes.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit d52ac53. Configure here.

@mydea

mydea commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Folded into #23833, which now contains this move plus the ServerRuntimeClient/node-stack-parser move as a single commit targeting develop.

@mydea mydea closed this Sep 2, 2026
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