Skip to content

Commit e727db4

Browse files
authored
fix(core): Wrap beforeSendLog in consoleSandbox (#16968)
resolves #16920 This will prevent recursive calls to `beforeSendLog` when using console logging instrumentation which will cause crashes.
1 parent bcb7422 commit e727db4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/core/src/logs/exports.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Scope, ScopeData } from '../scope';
77
import type { Log, SerializedLog, SerializedLogAttributeValue } from '../types-hoist/log';
88
import { mergeScopeData } from '../utils/applyScopeDataToEvent';
99
import { isParameterizedString } from '../utils/is';
10-
import { debug } from '../utils/logger';
10+
import { consoleSandbox, debug } from '../utils/logger';
1111
import { _getSpanForScope } from '../utils/spanOnScope';
1212
import { timestampInSeconds } from '../utils/time';
1313
import { SEVERITY_TEXT_TO_SEVERITY_NUMBER } from './constants';
@@ -168,7 +168,8 @@ export function _INTERNAL_captureLog(
168168

169169
client.emit('beforeCaptureLog', processedLog);
170170

171-
const log = beforeSendLog ? beforeSendLog(processedLog) : processedLog;
171+
// We need to wrap this in `consoleSandbox` to avoid recursive calls to `beforeSendLog`
172+
const log = beforeSendLog ? consoleSandbox(() => beforeSendLog(processedLog)) : processedLog;
172173
if (!log) {
173174
client.recordDroppedEvent('before_send', 'log_item', 1);
174175
DEBUG_BUILD && debug.warn('beforeSendLog returned null, log will not be captured.');

0 commit comments

Comments
 (0)