Skip to content

Commit 005a1c1

Browse files
committed
inline flush
1 parent ab208ca commit 005a1c1

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

packages/astro/src/server/middleware.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,18 @@ async function instrumentRequest(
193193
sendErrorToSentry(e);
194194
throw e;
195195
} finally {
196-
vercelWaitUntil(flushSafelyWithTimeout());
196+
vercelWaitUntil(
197+
(async () => {
198+
// Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.
199+
try {
200+
DEBUG_BUILD && logger.log('Flushing events...');
201+
await flush(2000);
202+
DEBUG_BUILD && logger.log('Done flushing events');
203+
} catch (e) {
204+
DEBUG_BUILD && logger.log('Error while flushing events:\n', e);
205+
}
206+
})(),
207+
);
197208
}
198209
// TODO: flush if serverless (first extract function)
199210
},
@@ -219,19 +230,6 @@ function addMetaTagToHead(htmlChunk: string): string {
219230
return htmlChunk.replace('<head>', content);
220231
}
221232

222-
/**
223-
* Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.
224-
*/
225-
export async function flushSafelyWithTimeout(): Promise<void> {
226-
try {
227-
DEBUG_BUILD && logger.log('Flushing events...');
228-
await flush(2000);
229-
DEBUG_BUILD && logger.log('Done flushing events');
230-
} catch (e) {
231-
DEBUG_BUILD && logger.log('Error while flushing events:\n', e);
232-
}
233-
}
234-
235233
/**
236234
* Interpolates the route from the URL and the passed params.
237235
* Best we can do to get a route name instead of a raw URL.

0 commit comments

Comments
 (0)