Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/astro/src/server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
captureException,
continueTrace,
flush,
getActiveSpan,
getClient,
getCurrentScope,
Expand All @@ -14,8 +15,10 @@ import {
import type { Scope, SpanAttributes } from '@sentry/types';
import {
addNonEnumerableProperty,
logger,
objectify,
stripUrlQueryAndFragment,
vercelWaitUntil,
winterCGRequestToRequestData,
} from '@sentry/utils';
import type { APIContext, MiddlewareResponseHandler } from 'astro';
Expand Down Expand Up @@ -188,6 +191,17 @@ async function instrumentRequest(
} catch (e) {
sendErrorToSentry(e);
throw e;
} finally {
vercelWaitUntil(
(async () => {
// Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.
try {
await flush(2000);
} catch (e) {
logger.log('Error while flushing events:\n', e);
}
})(),
);
}
// TODO: flush if serverless (first extract function)
},
Expand Down
Loading