ref(core)!: Remove startIdleSpan from server exports - #23420
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e82a7ec. Configure here.
size-limit report 📦
|
| * An idle span is always the active span. | ||
| */ | ||
| export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Partial<IdleSpanOptions> = {}): Span { | ||
| const client = getClient(); |
There was a problem hiding this comment.
Bug: The startIdleSpan function in core now unconditionally installs a browser-specific span streaming integration, which will cause issues if the function is called in a server environment.
Severity: MEDIUM
Suggested Fix
The startIdleSpan function should not unconditionally install the browser-specific integration. Instead, it should perform an environment check to ensure the correct integration is installed, or the responsibility for installing the appropriate integration should be moved to the environment-specific SDKs (browser/server) rather than being handled in shared core code.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/core/src/tracing/idleSpan.ts#L93
Potential issue: The `startIdleSpan` function, located in the shared
`packages/core/src/tracing/idleSpan.ts`, now unconditionally calls
`_INTERNAL_ensureBrowserSpanStreaming()`. This function proceeds to install a
browser-specific span streaming integration. Although `startIdleSpan` is intended for
browser environments, it remains accessible and exportable from the top-level
`@sentry/core` package. If a server-side SDK or a non-browser environment imports and
executes `startIdleSpan`, it will incorrectly install the browser integration. This
leads to a mismatch, as the browser integration depends on browser-specific APIs and
event handling mechanisms that are not present in a server environment, causing
incorrect behavior.
Did we get this right? 👍 / 👎 to inform future reviews.
9e30341 to
b6e0cb0
Compare
b6e0cb0 to
75ed06d
Compare

The
startIdleSpanAPI is exported from@sentry/corebut is only used in browser SDKs. It should not be used anywhere else. Therefore, this PR removes the API from@sentry/core/server. It can still be imported from the shared top-level exports because these re-export everything. Something I think we should change but I currently don't have the time to look at in more depth.