Skip to content

Commit 11c68d9

Browse files
author
Luca Forstner
authored
ref(node): Remove unnecessary emitters option from async context abstraction (#7849)
1 parent 3b3c5bd commit 11c68d9

File tree

4 files changed

+30
-49
lines changed

4 files changed

+30
-49
lines changed

packages/core/src/hub.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const DEFAULT_BREADCRUMBS = 100;
4545
export interface RunWithAsyncContextOptions {
4646
/** Whether to reuse an existing async context if one exists. Defaults to false. */
4747
reuseExisting?: boolean;
48-
/** Instances that should be referenced and retained in the new context */
49-
emitters?: unknown[];
5048
}
5149

5250
/**

packages/nextjs/src/server/wrapApiHandlerWithSentry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri
202202
throw objectifiedErr;
203203
}
204204
},
205-
{ emitters: [req, res] },
206205
);
207206

208207
// Since API route handlers are all async, nextjs always awaits the return value (meaning it's fine for us to return

packages/node/src/async/domain.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Carrier, Hub, RunWithAsyncContextOptions } from '@sentry/core';
22
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy, setHubOnCarrier } from '@sentry/core';
33
import * as domain from 'domain';
4-
import { EventEmitter } from 'events';
54

65
function getActiveDomain<T>(): T | undefined {
76
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
@@ -31,24 +30,12 @@ function runWithAsyncContext<T>(callback: (hub: Hub) => T, options: RunWithAsync
3130
const activeDomain = getActiveDomain<domain.Domain & Carrier>();
3231

3332
if (activeDomain && options?.reuseExisting) {
34-
for (const emitter of options.emitters || []) {
35-
if (emitter instanceof EventEmitter) {
36-
activeDomain.add(emitter);
37-
}
38-
}
39-
4033
// We're already in a domain, so we don't need to create a new one, just call the callback with the current hub
4134
return callback(getHubFromCarrier(activeDomain));
4235
}
4336

4437
const local = domain.create() as domain.Domain & Carrier;
4538

46-
for (const emitter of options.emitters || []) {
47-
if (emitter instanceof EventEmitter) {
48-
local.add(emitter);
49-
}
50-
}
51-
5239
const parentHub = activeDomain ? getHubFromCarrier(activeDomain) : undefined;
5340
const newHub = createNewHub(parentHub);
5441
setHubOnCarrier(local, newHub);

packages/node/src/handlers.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -187,43 +187,40 @@ export function requestHandler(
187187
});
188188
};
189189
}
190-
runWithAsyncContext(
191-
currentHub => {
192-
currentHub.configureScope(scope => {
193-
scope.setSDKProcessingMetadata({
194-
request: req,
195-
// TODO (v8): Stop passing this
196-
requestDataOptionsFromExpressHandler: requestDataOptions,
197-
});
190+
runWithAsyncContext(currentHub => {
191+
currentHub.configureScope(scope => {
192+
scope.setSDKProcessingMetadata({
193+
request: req,
194+
// TODO (v8): Stop passing this
195+
requestDataOptionsFromExpressHandler: requestDataOptions,
196+
});
198197

199-
const client = currentHub.getClient<NodeClient>();
200-
if (isAutoSessionTrackingEnabled(client)) {
201-
const scope = currentHub.getScope();
202-
if (scope) {
203-
// Set `status` of `RequestSession` to Ok, at the beginning of the request
204-
scope.setRequestSession({ status: 'ok' });
205-
}
198+
const client = currentHub.getClient<NodeClient>();
199+
if (isAutoSessionTrackingEnabled(client)) {
200+
const scope = currentHub.getScope();
201+
if (scope) {
202+
// Set `status` of `RequestSession` to Ok, at the beginning of the request
203+
scope.setRequestSession({ status: 'ok' });
206204
}
207-
});
205+
}
206+
});
208207

209-
res.once('finish', () => {
210-
const client = currentHub.getClient<NodeClient>();
211-
if (isAutoSessionTrackingEnabled(client)) {
212-
setImmediate(() => {
208+
res.once('finish', () => {
209+
const client = currentHub.getClient<NodeClient>();
210+
if (isAutoSessionTrackingEnabled(client)) {
211+
setImmediate(() => {
212+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
213+
if (client && (client as any)._captureRequestSession) {
214+
// Calling _captureRequestSession to capture request session at the end of the request by incrementing
215+
// the correct SessionAggregates bucket i.e. crashed, errored or exited
213216
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
214-
if (client && (client as any)._captureRequestSession) {
215-
// Calling _captureRequestSession to capture request session at the end of the request by incrementing
216-
// the correct SessionAggregates bucket i.e. crashed, errored or exited
217-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
218-
(client as any)._captureRequestSession();
219-
}
220-
});
221-
}
222-
});
223-
next();
224-
},
225-
{ emitters: [req, res] },
226-
);
217+
(client as any)._captureRequestSession();
218+
}
219+
});
220+
}
221+
});
222+
next();
223+
});
227224
};
228225
}
229226

0 commit comments

Comments
 (0)