1+ import { getGlobalSingleton } from '../carrier' ;
12import type { Client } from '../client' ;
23import { _getTraceInfoFromScope } from '../client' ;
34import { getClient , getCurrentScope , getGlobalScope , getIsolationScope } from '../currentScopes' ;
@@ -9,15 +10,11 @@ import { isParameterizedString } from '../utils/is';
910import { debug } from '../utils/logger' ;
1011import { _getSpanForScope } from '../utils/spanOnScope' ;
1112import { timestampInSeconds } from '../utils/time' ;
12- import { GLOBAL_OBJ } from '../utils/worldwide' ;
1313import { SEVERITY_TEXT_TO_SEVERITY_NUMBER } from './constants' ;
1414import { createLogEnvelope } from './envelope' ;
1515
1616const MAX_LOG_BUFFER_SIZE = 100 ;
1717
18- // The reference to the Client <> LogBuffer map is stored to ensure it's always the same
19- GLOBAL_OBJ . _sentryClientToLogBufferMap = new WeakMap < Client , Array < SerializedLog > > ( ) ;
20-
2118/**
2219 * Converts a log attribute to a serialized log attribute.
2320 *
@@ -92,11 +89,13 @@ function setLogAttribute(
9289 * the stable Sentry SDK API and can be changed or removed without warning.
9390 */
9491export function _INTERNAL_captureSerializedLog ( client : Client , serializedLog : SerializedLog ) : void {
92+ const bufferMap = _getBufferMap ( ) ;
93+
9594 const logBuffer = _INTERNAL_getLogBuffer ( client ) ;
9695 if ( logBuffer === undefined ) {
97- GLOBAL_OBJ . _sentryClientToLogBufferMap ? .set ( client , [ serializedLog ] ) ;
96+ bufferMap . set ( client , [ serializedLog ] ) ;
9897 } else {
99- GLOBAL_OBJ . _sentryClientToLogBufferMap ? .set ( client , [ ...logBuffer , serializedLog ] ) ;
98+ bufferMap . set ( client , [ ...logBuffer , serializedLog ] ) ;
10099 if ( logBuffer . length >= MAX_LOG_BUFFER_SIZE ) {
101100 _INTERNAL_flushLogsBuffer ( client , logBuffer ) ;
102101 }
@@ -217,7 +216,7 @@ export function _INTERNAL_flushLogsBuffer(client: Client, maybeLogBuffer?: Array
217216 const envelope = createLogEnvelope ( logBuffer , clientOptions . _metadata , clientOptions . tunnel , client . getDsn ( ) ) ;
218217
219218 // Clear the log buffer after envelopes have been constructed.
220- GLOBAL_OBJ . _sentryClientToLogBufferMap ? .set ( client , [ ] ) ;
219+ _getBufferMap ( ) . set ( client , [ ] ) ;
221220
222221 client . emit ( 'flushLogs' ) ;
223222
@@ -235,7 +234,7 @@ export function _INTERNAL_flushLogsBuffer(client: Client, maybeLogBuffer?: Array
235234 * @returns The log buffer for the given client.
236235 */
237236export function _INTERNAL_getLogBuffer ( client : Client ) : Array < SerializedLog > | undefined {
238- return GLOBAL_OBJ . _sentryClientToLogBufferMap ? .get ( client ) ;
237+ return _getBufferMap ( ) . get ( client ) ;
239238}
240239
241240/**
@@ -251,3 +250,8 @@ function getMergedScopeData(currentScope: Scope): ScopeData {
251250 mergeScopeData ( scopeData , currentScope . getScopeData ( ) ) ;
252251 return scopeData ;
253252}
253+
254+ function _getBufferMap ( ) : WeakMap < Client , Array < SerializedLog > > {
255+ // The reference to the Client <> LogBuffer map is stored on the carrier to ensure it's always the same
256+ return getGlobalSingleton ( 'clientToLogBufferMap' , ( ) => new WeakMap < Client , Array < SerializedLog > > ( ) ) ;
257+ }
0 commit comments