@@ -7,18 +7,17 @@ import {
77 SentryEvent ,
88 SentryEventHint ,
99 SentryResponse ,
10- SentryWrappedFunction ,
1110 Severity ,
1211 Status ,
1312} from '@sentry/types' ;
1413import { forget } from '@sentry/utils/async' ;
15- import { getGlobalObject , uuid4 } from '@sentry/utils/misc' ;
14+ import { logger } from '@sentry/utils/logger' ;
15+ import { consoleSandbox , uuid4 } from '@sentry/utils/misc' ;
1616import { truncate } from '@sentry/utils/string' ;
1717import { BackendClass } from './basebackend' ;
1818import { Dsn } from './dsn' ;
1919import { IntegrationIndex , setupIntegrations } from './integrations' ;
2020import { Backend , Client , Options } from './interfaces' ;
21- import { logger } from './logger' ;
2221
2322/**
2423 * Default maximum number of breadcrumbs added to an event. Can be overwritten
@@ -37,39 +36,6 @@ const MAX_BREADCRUMBS = 100;
3736 */
3837const MAX_URL_LENGTH = 250 ;
3938
40- /** JSDoc */
41- interface ExtensibleConsole extends Console {
42- [ key : string ] : any ;
43- }
44- /** JSDoc */
45- function beforeBreadcrumbConsoleLoopGuard ( callback : ( ) => Breadcrumb | null ) : Breadcrumb | null {
46- const global = getGlobalObject ( ) as Window ;
47- const levels = [ 'debug' , 'info' , 'warn' , 'error' , 'log' ] ;
48- if ( ! ( 'console' in global ) ) {
49- return callback ( ) ;
50- }
51- const originalConsole = global . console as ExtensibleConsole ;
52- const wrappedLevels : { [ key : string ] : any } = { } ;
53-
54- // Restore all wrapped console methods
55- levels . forEach ( level => {
56- if ( level in global . console && ( originalConsole [ level ] as SentryWrappedFunction ) . __sentry__ ) {
57- wrappedLevels [ level ] = ( originalConsole [ level ] as SentryWrappedFunction ) . __sentry_wrapped__ ;
58- originalConsole [ level ] = ( originalConsole [ level ] as SentryWrappedFunction ) . __sentry_original__ ;
59- }
60- } ) ;
61-
62- // Perform callback manipulations
63- const result = callback ( ) ;
64-
65- // Revert restoration to wrapped state
66- Object . keys ( wrappedLevels ) . forEach ( level => {
67- originalConsole [ level ] = wrappedLevels [ level ] ;
68- } ) ;
69-
70- return result ;
71- }
72-
7339/**
7440 * Base implementation for all JavaScript SDK clients.
7541 *
@@ -228,7 +194,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
228194 const timestamp = new Date ( ) . getTime ( ) / 1000 ;
229195 const mergedBreadcrumb = { timestamp, ...breadcrumb } ;
230196 const finalBreadcrumb = beforeBreadcrumb
231- ? beforeBreadcrumbConsoleLoopGuard ( ( ) => beforeBreadcrumb ( mergedBreadcrumb , hint ) )
197+ ? ( consoleSandbox ( ( ) => beforeBreadcrumb ( mergedBreadcrumb , hint ) ) as Breadcrumb | null )
232198 : mergedBreadcrumb ;
233199
234200 if ( finalBreadcrumb === null ) {
@@ -431,6 +397,11 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
431397 * @inheritDoc
432398 */
433399 public getIntegration < T extends Integration > ( integration : IntegrationClass < T > ) : T | null {
434- return ( this . integrations [ integration . id ] as T ) || null ;
400+ try {
401+ return ( this . integrations [ integration . id ] as T ) || null ;
402+ } catch ( _oO ) {
403+ logger . warn ( `Cannot retrieve integration ${ integration . id } from the current Client` ) ;
404+ return null ;
405+ }
435406 }
436407}
0 commit comments