diff --git a/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts b/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts index 60dfe0e8b421..e1a2238b05a1 100644 --- a/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts +++ b/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts @@ -12,12 +12,14 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, setCapturedScopesOnSpan, setHttpStatus, + vercelWaitUntil, winterCGHeadersToDict, withIsolationScope, withScope, } from '@sentry/core'; import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils'; import type { RouteHandlerContext } from './types'; +import { flushSafelyWithTimeout } from './utils/responseEnd'; import { commonObjectToIsolationScope } from './utils/tracingUtils'; /** @@ -92,6 +94,9 @@ export function wrapRouteHandlerWithSentry any>( }); } }, + () => { + vercelWaitUntil(flushSafelyWithTimeout()); + }, ); try {