Skip to content

Commit fe8043c

Browse files
authored
ref: Remove reuseExisting option for ACS (#10645)
We don't have this anymore in the new model.
1 parent eb11f34 commit fe8043c

File tree

11 files changed

+15
-90
lines changed

11 files changed

+15
-90
lines changed

packages/core/src/asyncContext.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { Hub, Integration } from '@sentry/types';
22
import { GLOBAL_OBJ } from '@sentry/utils';
33

4-
export interface RunWithAsyncContextOptions {
5-
/** Whether to reuse an existing async context if one exists. Defaults to false. */
6-
reuseExisting?: boolean;
7-
}
8-
94
/**
105
* @private Private API with no semver guarantees!
116
*
@@ -20,7 +15,7 @@ export interface AsyncContextStrategy {
2015
/**
2116
* Runs the supplied callback in its own async context.
2217
*/
23-
runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T;
18+
runWithAsyncContext<T>(callback: () => T): T;
2419
}
2520

2621
/**

packages/core/src/hub.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
} from '@sentry/types';
2323
import { GLOBAL_OBJ, consoleSandbox, dateTimestampInSeconds, isThenable, logger, uuid4 } from '@sentry/utils';
2424

25-
import type { AsyncContextStrategy, Carrier, RunWithAsyncContextOptions } from './asyncContext';
25+
import type { AsyncContextStrategy, Carrier } from './asyncContext';
2626
import { getMainCarrier, getSentryCarrier } from './asyncContext';
2727
import { DEFAULT_ENVIRONMENT } from './constants';
2828
import { DEBUG_BUILD } from './debug-build';
@@ -661,12 +661,12 @@ export function getCurrentHub(): HubInterface {
661661
* @param options Options to pass to the async context strategy
662662
* @returns The result of the callback
663663
*/
664-
export function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions = {}): T {
664+
export function runWithAsyncContext<T>(callback: () => T): T {
665665
// Get main carrier (global for every environment)
666666
const carrier = getMainCarrier();
667667

668668
const acs = getAsyncContextStrategy(carrier);
669-
return acs.runWithAsyncContext(callback, options);
669+
return acs.runWithAsyncContext(callback);
670670
}
671671

672672
function getGlobalHub(): HubInterface {
@@ -752,7 +752,7 @@ export function getAsyncContextStrategy(carrier: Carrier): AsyncContextStrategy
752752
function getHubStackAsyncContextStrategy(): AsyncContextStrategy {
753753
return {
754754
getCurrentHub: getGlobalHub,
755-
runWithAsyncContext: <T>(callback: () => T, _options: RunWithAsyncContextOptions = {}): T => {
755+
runWithAsyncContext: <T>(callback: () => T): T => {
756756
return callback();
757757
},
758758
};

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type { ClientClass } from './sdk';
22
export type { Layer } from './hub';
3-
export type { AsyncContextStrategy, Carrier, RunWithAsyncContextOptions } from './asyncContext';
3+
export type { AsyncContextStrategy, Carrier } from './asyncContext';
44
export type { OfflineStore, OfflineTransportOptions } from './transports/offline';
55
export type { ServerRuntimeClientOptions } from './server-runtime-client';
66
export type { RequestDataIntegrationOptions } from './integrations/requestdata';

packages/node/src/async/domain.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as domain from 'domain';
2-
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
2+
import type { Carrier } from '@sentry/core';
33
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy, setHubOnCarrier } from '@sentry/core';
44
import type { Hub } from '@sentry/types';
55

@@ -27,14 +27,9 @@ function createNewHub(parent: Hub | undefined): Hub {
2727
return getHubFromCarrier(carrier);
2828
}
2929

30-
function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T {
30+
function runWithAsyncContext<T>(callback: () => T): T {
3131
const activeDomain = getActiveDomain<domain.Domain & Carrier>();
3232

33-
if (activeDomain && options?.reuseExisting) {
34-
// We're already in a domain, so we don't need to create a new one, just call the callback with the current hub
35-
return callback();
36-
}
37-
3833
const local = domain.create() as domain.Domain & Carrier;
3934

4035
const parentHub = activeDomain ? getHubFromCarrier(activeDomain) : undefined;

packages/node/src/async/hooks.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
1+
import type { Carrier } from '@sentry/core';
22
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy } from '@sentry/core';
33
import type { Hub } from '@sentry/types';
44
import * as async_hooks from 'async_hooks';
@@ -33,15 +33,9 @@ export function setHooksAsyncContextStrategy(): void {
3333
return getHubFromCarrier(carrier);
3434
}
3535

36-
function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T {
36+
function runWithAsyncContext<T>(callback: () => T): T {
3737
const existingHub = getCurrentHub();
3838

39-
if (existingHub && options?.reuseExisting) {
40-
// We're already in an async context, so we don't need to create a new one
41-
// just call the callback with the current hub
42-
return callback();
43-
}
44-
4539
const newHub = createNewHub(existingHub);
4640

4741
return asyncStorage.run(newHub, () => {

packages/node/test/async/domain.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,6 @@ describe('setDomainAsyncContextStrategy()', () => {
160160
});
161161
});
162162

163-
test('within a domain reused when requested', () => {
164-
setDomainAsyncContextStrategy();
165-
166-
runWithAsyncContext(() => {
167-
const hub1 = getCurrentHub();
168-
runWithAsyncContext(
169-
() => {
170-
const hub2 = getCurrentHub();
171-
expect(hub1).toBe(hub2);
172-
},
173-
{ reuseExisting: true },
174-
);
175-
});
176-
});
177-
178163
test('concurrent hub contexts', done => {
179164
setDomainAsyncContextStrategy();
180165

packages/node/test/async/hooks.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,6 @@ describe('setHooksAsyncContextStrategy()', () => {
166166
});
167167
});
168168

169-
test('context within a context reused when requested', () => {
170-
setHooksAsyncContextStrategy();
171-
172-
runWithAsyncContext(() => {
173-
const hub1 = getCurrentHub();
174-
runWithAsyncContext(
175-
() => {
176-
const hub2 = getCurrentHub();
177-
expect(hub1).toBe(hub2);
178-
},
179-
{ reuseExisting: true },
180-
);
181-
});
182-
});
183-
184169
test('concurrent hub contexts', done => {
185170
setHooksAsyncContextStrategy();
186171

packages/opentelemetry/src/asyncContextStrategy.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as api from '@opentelemetry/api';
2-
import type { Hub, RunWithAsyncContextOptions } from '@sentry/core';
2+
import type { Hub } from '@sentry/core';
33
import { setAsyncContextStrategy } from '@sentry/core';
44
import { SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY } from './constants';
55

@@ -19,15 +19,7 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void {
1919
}
2020

2121
/* This is more or less a NOOP - we rely on the OTEL context manager for this */
22-
function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T {
23-
const existingHub = getCurrentHub();
24-
25-
if (existingHub && options?.reuseExisting) {
26-
// We're already in an async context, so we don't need to create a new one
27-
// just call the callback with the current hub
28-
return callback();
29-
}
30-
22+
function runWithAsyncContext<T>(callback: () => T): T {
3123
const ctx = api.context.active();
3224

3325
// We depend on the otelContextManager to handle the context/hub

packages/opentelemetry/test/asyncContextStrategy.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,6 @@ describe('asyncContextStrategy', () => {
111111
});
112112
});
113113

114-
test('context within a context reused when requested', () => {
115-
runWithAsyncContext(() => {
116-
// eslint-disable-next-line deprecation/deprecation
117-
const hub1 = getCurrentHub();
118-
runWithAsyncContext(
119-
() => {
120-
// eslint-disable-next-line deprecation/deprecation
121-
const hub2 = getCurrentHub();
122-
expect(hub1).toBe(hub2);
123-
},
124-
{ reuseExisting: true },
125-
);
126-
});
127-
});
128-
129114
test('concurrent hub contexts', done => {
130115
let d1done = false;
131116
let d2done = false;

packages/serverless/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { addExceptionMechanism } from '@sentry/utils';
77
* @returns function which runs in the newly created domain or in the existing one
88
*/
99
export function domainify<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R | void {
10-
return (...args) => runWithAsyncContext(() => fn(...args), { reuseExisting: true });
10+
return (...args) => runWithAsyncContext(() => fn(...args));
1111
}
1212

1313
/**

packages/vercel-edge/src/async.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
1+
import type { Carrier } from '@sentry/core';
22
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy } from '@sentry/core';
33
import type { Hub } from '@sentry/types';
44
import { GLOBAL_OBJ, logger } from '@sentry/utils';
@@ -42,15 +42,9 @@ export function setAsyncLocalStorageAsyncContextStrategy(): void {
4242
return getHubFromCarrier(carrier);
4343
}
4444

45-
function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T {
45+
function runWithAsyncContext<T>(callback: () => T): T {
4646
const existingHub = getCurrentHub();
4747

48-
if (existingHub && options?.reuseExisting) {
49-
// We're already in an async context, so we don't need to create a new one
50-
// just call the callback with the current hub
51-
return callback();
52-
}
53-
5448
const newHub = createNewHub(existingHub);
5549

5650
return asyncStorage.run(newHub, () => {

0 commit comments

Comments
 (0)