@@ -458,28 +458,31 @@ export function getCurrentHub(): Hub {
458
458
}
459
459
460
460
/**
461
- * Try to read the hub from an active domain, fallback to the registry if one doesnt exist
461
+ * Returns the active domain, if one exists
462
+ *
463
+ * @returns The domain, or undefined if there is no active domain
464
+ */
465
+ export function getActiveDomain ( ) : any | undefined {
466
+ const sentry = getMainCarrier ( ) . __SENTRY__ ;
467
+
468
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
469
+ return sentry && sentry . extensions && sentry . extensions . domain && ( sentry . extensions . domain as any ) . active ;
470
+ }
471
+
472
+ /**
473
+ * Try to read the hub from an active domain, and fallback to the registry if one doesn't exist
462
474
* @returns discovered hub
463
475
*/
464
476
function getHubFromActiveDomain ( registry : Carrier ) : Hub {
465
477
try {
466
- const property = 'domain' ;
467
- const carrier = getMainCarrier ( ) ;
468
- const sentry = carrier . __SENTRY__ ;
469
- if ( ! sentry || ! sentry . extensions || ! sentry . extensions [ property ] ) {
470
- return getHubFromCarrier ( registry ) ;
471
- }
472
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
473
- const domain = sentry . extensions [ property ] as any ;
474
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
475
- const activeDomain = domain . active ;
478
+ const activeDomain = getActiveDomain ( ) ;
476
479
477
480
// If there's no active domain, just return global hub
478
481
if ( ! activeDomain ) {
479
482
return getHubFromCarrier ( registry ) ;
480
483
}
481
484
482
- // If there's no hub on current domain, or its an old API, assign a new one
485
+ // If there's no hub on current domain, or it's an old API, assign a new one
483
486
if ( ! hasHubOnCarrier ( activeDomain ) || getHubFromCarrier ( activeDomain ) . isOlderThan ( API_VERSION ) ) {
484
487
const registryHubTopStack = getHubFromCarrier ( registry ) . getStackTop ( ) ;
485
488
setHubOnCarrier ( activeDomain , new Hub ( registryHubTopStack . client , Scope . clone ( registryHubTopStack . scope ) ) ) ;
0 commit comments