|
1 |
| -import type { Client, Scope as ScopeInterface } from '@sentry/types'; |
2 |
| -import { isThenable } from '@sentry/utils'; |
| 1 | +import type { Client, Hub, Scope as ScopeInterface } from '@sentry/types'; |
| 2 | +import { GLOBAL_OBJ, getGlobalSingleton, isThenable, logger } from '@sentry/utils'; |
3 | 3 | import { getDefaultCurrentScope, getDefaultIsolationScope } from '../currentScopes';
|
4 | 4 | import { Scope } from '../scope';
|
5 | 5 |
|
6 |
| -import { getMainCarrier, getSentryCarrier } from './../carrier'; |
| 6 | +import { Carrier, getMainCarrier, getSentryCarrier } from '../carrier'; |
| 7 | +import { getCurrentHubShim } from '../getCurrentHubShim'; |
7 | 8 | import type { AsyncContextStrategy } from './types';
|
8 | 9 |
|
9 | 10 | interface Layer {
|
@@ -104,16 +105,6 @@ export class AsyncContextStack {
|
104 | 105 | return this._stack[this._stack.length - 1];
|
105 | 106 | }
|
106 | 107 |
|
107 |
| - /** |
108 |
| - * Only here for compatibility with <v8 versions |
109 |
| - * @deprecated DO NOT use this function |
110 |
| - * @hidden |
111 |
| - * @internal |
112 |
| - */ |
113 |
| - public isOlderThan(_version: number): boolean { |
114 |
| - return false; |
115 |
| - } |
116 |
| - |
117 | 108 | /**
|
118 | 109 | * Push a scope to the stack.
|
119 | 110 | */
|
@@ -141,20 +132,17 @@ export class AsyncContextStack {
|
141 | 132 | * This will be removed during the v8 cycle and is only here to make migration easier.
|
142 | 133 | */
|
143 | 134 | function getAsyncContextStack(): AsyncContextStack {
|
144 |
| - const registry = getMainCarrier(); |
145 |
| - |
146 |
| - // For now we continue to keep this as `hub` on the ACS, |
147 |
| - // as e.g. the Loader Script relies on this. |
148 |
| - // Eventually we may change this if/when we update the loader to not require this field anymore |
149 |
| - // Related, we also write to `hub` in {@link ./../sdk.ts registerClientOnGlobalHub} |
150 |
| - const sentry = getSentryCarrier(registry) as { hub?: AsyncContextStack }; |
151 |
| - |
152 |
| - if (sentry.hub) { |
153 |
| - return sentry.hub; |
| 135 | + // eslint-disable-next-line deprecation/deprecation |
| 136 | + const sentry = getSentryCarrier(getMainCarrier()) as { hub?: AsyncContextStack }; |
| 137 | + if (!sentry.hub) { |
| 138 | + // For now, we still set the `hub` object to gracefully handle pre v8 SDKs and certain scripts |
| 139 | + // (e.g. our loader script) accessing properties on `window.__SENTRY__.hub`. |
| 140 | + // This will just call the `getCurrentHubShim` function, as if users would interact with `getCurrentHub`. |
| 141 | + // eslint-disable-next-line deprecation/deprecation |
| 142 | + Object.defineProperty(sentry, 'hub', { get: () => getCurrentHubShim(), enumerable: true }); |
154 | 143 | }
|
155 | 144 |
|
156 |
| - sentry.hub = new AsyncContextStack(getDefaultCurrentScope(), getDefaultIsolationScope()); |
157 |
| - return sentry.hub; |
| 145 | + return getGlobalSingleton('stack', () => new AsyncContextStack(getDefaultCurrentScope(), getDefaultIsolationScope())); |
158 | 146 | }
|
159 | 147 |
|
160 | 148 | function withScope<T>(callback: (scope: ScopeInterface) => T): T {
|
|
0 commit comments