File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -415,13 +415,18 @@ export class Hub implements HubInterface {
415
415
* @inheritDoc
416
416
*/
417
417
public endSession ( ) : void {
418
- this . getStackTop ( )
419
- ?. scope ?. getSession ( )
420
- ?. close ( ) ;
418
+ const layer = this . getStackTop ( ) ;
419
+ const scope = layer && layer . scope ;
420
+ const session = scope && scope . getSession ( ) ;
421
+ if ( session ) {
422
+ session . close ( ) ;
423
+ }
421
424
this . _sendSessionUpdate ( ) ;
422
425
423
426
// the session is over; take it off of the scope
424
- this . getStackTop ( ) ?. scope ?. setSession ( ) ;
427
+ if ( scope ) {
428
+ scope . setSession ( ) ;
429
+ }
425
430
}
426
431
427
432
/**
@@ -575,7 +580,8 @@ export function getActiveDomain(): DomainAsCarrier | undefined {
575
580
*/
576
581
function getHubFromActiveDomain ( registry : Carrier ) : Hub {
577
582
try {
578
- const activeDomain = getMainCarrier ( ) . __SENTRY__ ?. extensions ?. domain ?. active ;
583
+ const sentry = getMainCarrier ( ) . __SENTRY__ ;
584
+ const activeDomain = sentry && sentry . extensions && sentry . extensions . domain && sentry . extensions . domain . active ;
579
585
580
586
// If there's no active domain, just return global hub
581
587
if ( ! activeDomain ) {
Original file line number Diff line number Diff line change @@ -264,12 +264,12 @@ export class Scope implements ScopeInterface {
264
264
const span = this . getSpan ( ) as undefined | ( Span & { spanRecorder : { spans : Span [ ] } } ) ;
265
265
266
266
// try it the new way first
267
- if ( span ? .transaction ) {
268
- return span ? .transaction ;
267
+ if ( span && span . transaction ) {
268
+ return span . transaction ;
269
269
}
270
270
271
271
// fallback to the old way (known bug: this only finds transactions with sampled = true)
272
- if ( span ? .spanRecorder ? .spans [ 0 ] ) {
272
+ if ( span && span . spanRecorder && span . spanRecorder . spans [ 0 ] ) {
273
273
return span . spanRecorder . spans [ 0 ] as Transaction ;
274
274
}
275
275
@@ -430,7 +430,7 @@ export class Scope implements ScopeInterface {
430
430
// errors with transaction and it relies on that.
431
431
if ( this . _span ) {
432
432
event . contexts = { trace : this . _span . getTraceContext ( ) , ...event . contexts } ;
433
- const transactionName = this . _span . transaction ? .name ;
433
+ const transactionName = this . _span . transaction && this . _span . transaction . name ;
434
434
if ( transactionName ) {
435
435
event . tags = { transaction : transactionName , ...event . tags } ;
436
436
}
Original file line number Diff line number Diff line change @@ -83,14 +83,15 @@ export class SessionFlusher implements SessionFlusherLike {
83
83
return ;
84
84
}
85
85
const scope = getCurrentHub ( ) . getScope ( ) ;
86
- const requestSession = scope ? .getRequestSession ( ) ;
86
+ const requestSession = scope && scope . getRequestSession ( ) ;
87
87
88
88
if ( requestSession && requestSession . status ) {
89
89
this . _incrementSessionStatusCount ( requestSession . status , new Date ( ) ) ;
90
90
// This is not entirely necessarily but is added as a safe guard to indicate the bounds of a request and so in
91
91
// case captureRequestSession is called more than once to prevent double count
92
- scope ?. setRequestSession ( undefined ) ;
93
-
92
+ if ( scope ) {
93
+ scope . setRequestSession ( undefined ) ;
94
+ }
94
95
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
95
96
}
96
97
}
You can’t perform that action at this time.
0 commit comments