diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 9d731b90296d..18527e342d12 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -45,8 +45,6 @@ const DEFAULT_BREADCRUMBS = 100; export interface RunWithAsyncContextOptions { /** Whether to reuse an existing async context if one exists. Defaults to false. */ reuseExisting?: boolean; - /** Instances that should be referenced and retained in the new context */ - emitters?: unknown[]; } /** diff --git a/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts index b1388352c039..3799ff94905a 100644 --- a/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts +++ b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts @@ -202,7 +202,6 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri throw objectifiedErr; } }, - { emitters: [req, res] }, ); // Since API route handlers are all async, nextjs always awaits the return value (meaning it's fine for us to return diff --git a/packages/node/src/async/domain.ts b/packages/node/src/async/domain.ts index 371b2451e1b8..c53f7a7e22fc 100644 --- a/packages/node/src/async/domain.ts +++ b/packages/node/src/async/domain.ts @@ -1,7 +1,6 @@ import type { Carrier, Hub, RunWithAsyncContextOptions } from '@sentry/core'; import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy, setHubOnCarrier } from '@sentry/core'; import * as domain from 'domain'; -import { EventEmitter } from 'events'; function getActiveDomain(): T | undefined { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any @@ -31,24 +30,12 @@ function runWithAsyncContext(callback: (hub: Hub) => T, options: RunWithAsync const activeDomain = getActiveDomain(); if (activeDomain && options?.reuseExisting) { - for (const emitter of options.emitters || []) { - if (emitter instanceof EventEmitter) { - activeDomain.add(emitter); - } - } - // We're already in a domain, so we don't need to create a new one, just call the callback with the current hub return callback(getHubFromCarrier(activeDomain)); } const local = domain.create() as domain.Domain & Carrier; - for (const emitter of options.emitters || []) { - if (emitter instanceof EventEmitter) { - local.add(emitter); - } - } - const parentHub = activeDomain ? getHubFromCarrier(activeDomain) : undefined; const newHub = createNewHub(parentHub); setHubOnCarrier(local, newHub); diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 6fc43d574df6..0a0ddee02a75 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -187,43 +187,40 @@ export function requestHandler( }); }; } - runWithAsyncContext( - currentHub => { - currentHub.configureScope(scope => { - scope.setSDKProcessingMetadata({ - request: req, - // TODO (v8): Stop passing this - requestDataOptionsFromExpressHandler: requestDataOptions, - }); + runWithAsyncContext(currentHub => { + currentHub.configureScope(scope => { + scope.setSDKProcessingMetadata({ + request: req, + // TODO (v8): Stop passing this + requestDataOptionsFromExpressHandler: requestDataOptions, + }); - const client = currentHub.getClient(); - if (isAutoSessionTrackingEnabled(client)) { - const scope = currentHub.getScope(); - if (scope) { - // Set `status` of `RequestSession` to Ok, at the beginning of the request - scope.setRequestSession({ status: 'ok' }); - } + const client = currentHub.getClient(); + if (isAutoSessionTrackingEnabled(client)) { + const scope = currentHub.getScope(); + if (scope) { + // Set `status` of `RequestSession` to Ok, at the beginning of the request + scope.setRequestSession({ status: 'ok' }); } - }); + } + }); - res.once('finish', () => { - const client = currentHub.getClient(); - if (isAutoSessionTrackingEnabled(client)) { - setImmediate(() => { + res.once('finish', () => { + const client = currentHub.getClient(); + if (isAutoSessionTrackingEnabled(client)) { + setImmediate(() => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (client && (client as any)._captureRequestSession) { + // Calling _captureRequestSession to capture request session at the end of the request by incrementing + // the correct SessionAggregates bucket i.e. crashed, errored or exited // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - if (client && (client as any)._captureRequestSession) { - // Calling _captureRequestSession to capture request session at the end of the request by incrementing - // the correct SessionAggregates bucket i.e. crashed, errored or exited - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - (client as any)._captureRequestSession(); - } - }); - } - }); - next(); - }, - { emitters: [req, res] }, - ); + (client as any)._captureRequestSession(); + } + }); + } + }); + next(); + }); }; }