fix(console): Re-patch console in AWS Lambda runtimes#20337
fix(console): Re-patch console in AWS Lambda runtimes#20337
Conversation
size-limit report 📦
|
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 487e210. Configure here.
| } else { | ||
| // Accept as-is: consoleSandbox restores, other Sentry wrappers, or non-functions | ||
| current = newValue; | ||
| } |
There was a problem hiding this comment.
Infinite recursion when third-party code wraps console
High Severity
The setter creates an infinite recursion when any third-party code wraps a console method using the common capture-and-call pattern (e.g. const prev = console.log; console.log = (...args) => { prev(...args); }). The setter treats the new function as a Lambda replacement, sets underlying = newFunc and keeps current = wrapper. Now calling console.log invokes wrapper → underlying (newFunc) → captured prev (which IS wrapper) → underlying (newFunc) → … causing a stack overflow. The Lambda runtime avoids this because it fully replaces the method without calling the previous one, but any other library or user code that wraps console the standard way in a Lambda environment will trigger this crash.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 487e210. Configure here.
| import: createImport('init', 'metrics', 'logger'), | ||
| gzip: true, | ||
| limit: '28 KB', | ||
| limit: '30 KB', |
There was a problem hiding this comment.
Lambda-only code increases browser bundle sizes
Low Severity
The patchWithDefineProperty function and its runtime process.env.LAMBDA_TASK_ROOT check live in @sentry/core, so they're bundled into all browser packages despite being Lambda-specific dead code. The gzipped @sentry/browser limit increased from 28KB to 30KB (~7%). Tree shaking can't eliminate the function because the branch is a runtime check. The PR author noted this might belong in @sentry/node instead. Flagging per project rules on large browser bundle size increases.
Additional Locations (1)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 487e210. Configure here.


On AWS Lambda, the Node.js runtime replaces
console.*methods with its own loggers. This means Sentry's console instrumentation gets silently overwritten, and integrations likeconsoleLoggingIntegrationstop capturing console output entirely.This PR fixes that by introducing a
defineProperty-based patching strategy for Lambda environments. Instead of simply assigning a wrapper toconsole.log(which Lambda can overwrite), we define a getter/setter on the console property. When the Lambda runtime assigns its logger, the setter intercepts it, stores the new function as the underlying delegate, and keeps Sentry's wrapper in place. The handler continues to fire, and the Lambda logger still gets called underneath (I checked that manually - the log is still shown in the CloudWatch logs).This behavior is guarded behind
process.env.LAMBDA_TASK_ROOT, so non-Lambda environments continue to use the existingfill()-based patching with zero behavioral change. IfdefinePropertyfails for any reason, it falls back tofill().The setter also handles
consoleSandboxcorrectly (recognizes when it restores the original method and allows it through), and defers to other Sentry wrappers by checking for__sentry_original__.It adds a bit to bundle size, maybe it's worth re-exporting this from
@sentry/node🤔Closes #18238