@@ -12,9 +12,9 @@ import {
12
12
import {
13
13
dateTimestampInSeconds ,
14
14
getEventDescription ,
15
+ Logger ,
15
16
isPlainObject ,
16
17
isPrimitive ,
17
- logger ,
18
18
normalize ,
19
19
truncate ,
20
20
uuid4 ,
@@ -67,6 +67,9 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
67
67
/** Options passed to the SDK. */
68
68
public readonly options : O ;
69
69
70
+ /** Logger used for debug mode */
71
+ public readonly logger = new Logger ( 'Client' ) ;
72
+
70
73
/** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */
71
74
public readonly dsn ?: Dsn ;
72
75
@@ -88,10 +91,14 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
88
91
* @param options Options for the client.
89
92
*/
90
93
protected constructor ( options : O ) {
91
- this . options = options ;
94
+ this . options = options ?? { } ;
95
+
96
+ if ( this . options . dsn ) {
97
+ this . dsn = new Dsn ( this . options . dsn ) ;
98
+ }
92
99
93
- if ( options . dsn ) {
94
- this . dsn = new Dsn ( options . dsn ) ;
100
+ if ( this . options . debug ) {
101
+ this . logger . enabled = true ;
95
102
}
96
103
97
104
this . _transport = this . _setupTransport ( ) ;
@@ -155,7 +162,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
155
162
*/
156
163
public captureSession ( session : Session ) : void {
157
164
if ( ! session . release ) {
158
- logger . warn ( 'Discarded session because of missing release' ) ;
165
+ this . logger . warn ( 'Discarded session because of missing release' ) ;
159
166
} else {
160
167
this . _sendSession ( session ) ;
161
168
// After sending, we set init false to inidcate it's not the first occurence
@@ -206,7 +213,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
206
213
return integrations . reduce ( ( integrationsIndex : Record < string , Integration > , integration ) => {
207
214
integrationsIndex [ integration . name ] = integration ;
208
215
integration . install ( this ) ;
209
- logger . log ( `Integration installed: ${ integration . name } ` ) ;
216
+ this . logger . log ( `Integration installed: ${ integration . name } ` ) ;
210
217
return integrationsIndex ;
211
218
} , { } ) ;
212
219
}
@@ -217,7 +224,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
217
224
// TODO: Do we need generic here?
218
225
protected _sendRequest < T > ( request : TransportRequest < T > ) : void {
219
226
this . _transport . sendRequest ( request ) . then ( null , reason => {
220
- logger . error ( `Failed sending request: ${ reason } ` ) ;
227
+ this . logger . error ( `Failed sending request: ${ reason } ` ) ;
221
228
} ) ;
222
229
}
223
230
@@ -431,7 +438,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
431
438
// eslint-disable-next-line complexity
432
439
protected _processEvent ( event : SentryEvent , captureContext : CaptureContext ) : SentryEvent | null {
433
440
if ( this . options . enabled === false ) {
434
- logger . error ( 'SDK not enabled, will not send event.' ) ;
441
+ this . logger . error ( 'SDK not enabled, will not send event.' ) ;
435
442
return null ;
436
443
}
437
444
@@ -440,7 +447,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
440
447
// 0.0 === 0% events are sent
441
448
// Sampling for transaction happens somewhere else
442
449
if ( ! isTransaction && typeof this . options . sampleRate === 'number' && Math . random ( ) > this . options . sampleRate ) {
443
- logger . error (
450
+ this . logger . error (
444
451
`Discarding event because it's not included in the random sample (sampling rate = ${ this . options . sampleRate } )` ,
445
452
) ;
446
453
return null ;
@@ -466,23 +473,23 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
466
473
467
474
processedEvent = scope . applyToEvent ( processedEvent , captureContext . hint ) ;
468
475
if ( processedEvent === null ) {
469
- logger . error ( 'A scope event processor returned null, will not send event.' ) ;
476
+ this . logger . error ( 'A scope event processor returned null, will not send event.' ) ;
470
477
return null ;
471
478
}
472
479
473
480
for ( const processor of this . _eventProcessors ) {
474
481
if ( typeof processor === 'function' ) {
475
482
const nextEvent = processor ( processedEvent , captureContext . hint ) ;
476
483
if ( nextEvent === null ) {
477
- logger . error ( 'A client event processor returned null, will not send event.' ) ;
484
+ this . logger . error ( 'A client event processor returned null, will not send event.' ) ;
478
485
return null ;
479
486
}
480
487
processedEvent = nextEvent ;
481
488
}
482
489
}
483
490
484
491
if ( processedEvent === null ) {
485
- logger . error ( 'A scope event processor returned null, will not send event.' ) ;
492
+ this . logger . error ( 'A scope event processor returned null, will not send event.' ) ;
486
493
return null ;
487
494
}
488
495
@@ -499,12 +506,12 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
499
506
processedEvent = this . options . beforeSend ( processedEvent as SentryEvent , captureContext ?. hint ) ;
500
507
501
508
if ( ! ( isPlainObject ( processedEvent ) || processedEvent === null ) ) {
502
- logger . error ( '`beforeSend` method has to return `null` or a valid event.' ) ;
509
+ this . logger . error ( '`beforeSend` method has to return `null` or a valid event.' ) ;
503
510
return null ;
504
511
}
505
512
506
513
if ( processedEvent === null ) {
507
- logger . error ( '`beforeSend` returned `null`, will not send event.' ) ;
514
+ this . logger . error ( '`beforeSend` returned `null`, will not send event.' ) ;
508
515
return null ;
509
516
}
510
517
@@ -525,7 +532,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
525
532
originalException : e ,
526
533
} ,
527
534
} ) ;
528
- logger . error (
535
+ this . logger . error (
529
536
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${ e } ` ,
530
537
) ;
531
538
return null ;
0 commit comments