Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Prevent infinite recursion when console is instrumented twice#21959
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
Merged
Lms24
merged 5 commits into
develop
from
fix/console-instrumentation-double-wrap-recursionJul 16, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a3e1df4
fix(core): Prevent infinite recursion when console is instrumented twice
antonis 430f73e
fix(core): Guard console instrumentation per SDK copy, not via shared…
antonis ddf0b97
Merge branch 'develop' into fix/console-instrumentation-double-wrap-r…
antonis e771392
test(core): Isolate console instrumentation tests with vi.resetModules
antonis 685f197
test(core): Avoid forbidden import() type annotation in console test
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -51,16 +51,31 @@ export function _INTERNAL_resetConsoleInstrumentationOptions(): void { | ||
| _filter.clear(); | ||
| } | ||
| function instrumentConsole(): void { | ||
| // The console levels *this* copy of the SDK has already wrapped. A copy must wrap each level at | ||
| // most once: re-wrapping overwrites `originalConsoleMethods[level]` with a function that itself | ||
| // reads `originalConsoleMethods[level]`, so calling through to the "original" (here and in | ||
| // `consoleSandbox`) re-enters a wrapper indefinitely, ending in a `RangeError: Maximum call stack | ||
| // size exceeded`. This can happen e.g. in React Native when instrumentation state is re-initialized | ||
| // while the console stays wrapped. See getsentry/sentry-react-native SDK-CRASHES-REACT-NATIVE-5HZ. | ||
| // We intentionally track this per copy rather than checking for the shared `__sentry_original__` | ||
| // marker: a *different* SDK copy's wrapper (e.g. separate CDN bundles that each inline | ||
| // `@sentry/core`) is safe to wrap since its call chain resolves down to the native method, and | ||
| // skipping it would silently drop that copy's console handlers (breadcrumbs, `captureConsole`). | ||
| const instrumentedLevels = new Set<ConsoleLevel>(); | ||
sentry[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** Only exported for tests. */ | ||
| export function instrumentConsole(): void { | ||
| if (!('console' in GLOBAL_OBJ)) { | ||
| return; | ||
| } | ||
| CONSOLE_LEVELS.forEach(function (level: ConsoleLevel): void { | ||
| if (!(level in GLOBAL_OBJ.console)) { | ||
| if (instrumentedLevels.has(level) || !(level in GLOBAL_OBJ.console)) { | ||
| return; | ||
| } | ||
| instrumentedLevels.add(level); | ||
| fill(GLOBAL_OBJ.console, level, function (originalConsoleMethod: () => any): Function { | ||
| originalConsoleMethods[level] = originalConsoleMethod; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.