Skip to content

Commit

Permalink
ref(hub): Simplify getting hub from active domain (#3227)
Browse files Browse the repository at this point in the history
Also deprecate the resulting unused function and interface.
  • Loading branch information
lobsterkatie committed Feb 2, 2021
1 parent ec7961c commit 24d2b4b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,13 @@ export function getCurrentHub(): Hub {

/**
* Returns the active domain, if one exists
*
* @deprecated No longer used; remove in v7
* @returns The domain, or undefined if there is no active domain
*/
// eslint-disable-next-line deprecation/deprecation
export function getActiveDomain(): DomainAsCarrier | undefined {
logger.warn('Function `getActiveDomain` is deprecated and will be removed in a future version.');

const sentry = getMainCarrier().__SENTRY__;

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

// If there's no active domain, just return global hub
if (!activeDomain) {
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// eslint-disable-next-line deprecation/deprecation
export { Carrier, DomainAsCarrier, Layer } from './interfaces';
export { addGlobalEventProcessor, Scope } from './scope';
export { Session } from './session';
export {
// eslint-disable-next-line deprecation/deprecation
getActiveDomain,
getCurrentHub,
getHubFromCarrier,
Expand Down
4 changes: 4 additions & 0 deletions packages/hub/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface Carrier {
};
}

/**
* @hidden
* @deprecated Can be removed once `Hub.getActiveDomain` is removed.
*/
export interface DomainAsCarrier extends Carrier {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
members: { [key: string]: any }[];
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export interface SamplingContext extends CustomSamplingContext {
parentSampled?: boolean;

/**
* Object representing the URL of the current page or worker script. Passed by default in a browser or service worker
* context.
* Object representing the URL of the current page or worker script. Passed by default when using the `BrowserTracing`
* integration.
*/
location?: WorkerLocation;

Expand Down

0 comments on commit 24d2b4b

Please sign in to comment.