Skip to content

Commit 24d2b4b

Browse files
authored
ref(hub): Simplify getting hub from active domain (#3227)
Also deprecate the resulting unused function and interface.
1 parent ec7961c commit 24d2b4b

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

packages/hub/src/hub.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,13 @@ export function getCurrentHub(): Hub {
473473

474474
/**
475475
* Returns the active domain, if one exists
476-
*
476+
* @deprecated No longer used; remove in v7
477477
* @returns The domain, or undefined if there is no active domain
478478
*/
479+
// eslint-disable-next-line deprecation/deprecation
479480
export function getActiveDomain(): DomainAsCarrier | undefined {
481+
logger.warn('Function `getActiveDomain` is deprecated and will be removed in a future version.');
482+
480483
const sentry = getMainCarrier().__SENTRY__;
481484

482485
return sentry && sentry.extensions && sentry.extensions.domain && sentry.extensions.domain.active;
@@ -488,7 +491,7 @@ export function getActiveDomain(): DomainAsCarrier | undefined {
488491
*/
489492
function getHubFromActiveDomain(registry: Carrier): Hub {
490493
try {
491-
const activeDomain = getActiveDomain();
494+
const activeDomain = getMainCarrier().__SENTRY__?.extensions?.domain?.active;
492495

493496
// If there's no active domain, just return global hub
494497
if (!activeDomain) {

packages/hub/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// eslint-disable-next-line deprecation/deprecation
12
export { Carrier, DomainAsCarrier, Layer } from './interfaces';
23
export { addGlobalEventProcessor, Scope } from './scope';
34
export { Session } from './session';
45
export {
6+
// eslint-disable-next-line deprecation/deprecation
57
getActiveDomain,
68
getCurrentHub,
79
getHubFromCarrier,

packages/hub/src/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export interface Carrier {
3434
};
3535
}
3636

37+
/**
38+
* @hidden
39+
* @deprecated Can be removed once `Hub.getActiveDomain` is removed.
40+
*/
3741
export interface DomainAsCarrier extends Carrier {
3842
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3943
members: { [key: string]: any }[];

packages/types/src/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export interface SamplingContext extends CustomSamplingContext {
9494
parentSampled?: boolean;
9595

9696
/**
97-
* Object representing the URL of the current page or worker script. Passed by default in a browser or service worker
98-
* context.
97+
* Object representing the URL of the current page or worker script. Passed by default when using the `BrowserTracing`
98+
* integration.
9999
*/
100100
location?: WorkerLocation;
101101

0 commit comments

Comments
 (0)