File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
packages/astro/src/server Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 33 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
44 captureException ,
55 continueTrace ,
6+ flush ,
67 getActiveSpan ,
78 getClient ,
89 getCurrentScope ,
@@ -14,8 +15,10 @@ import {
1415import type { Scope , SpanAttributes } from '@sentry/types' ;
1516import {
1617 addNonEnumerableProperty ,
18+ logger ,
1719 objectify ,
1820 stripUrlQueryAndFragment ,
21+ vercelWaitUntil ,
1922 winterCGRequestToRequestData ,
2023} from '@sentry/utils' ;
2124import type { APIContext , MiddlewareResponseHandler } from 'astro' ;
@@ -188,6 +191,17 @@ async function instrumentRequest(
188191 } catch ( e ) {
189192 sendErrorToSentry ( e ) ;
190193 throw e ;
194+ } finally {
195+ vercelWaitUntil (
196+ ( async ( ) => {
197+ // Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.
198+ try {
199+ await flush ( 2000 ) ;
200+ } catch ( e ) {
201+ logger . log ( 'Error while flushing events:\n' , e ) ;
202+ }
203+ } ) ( ) ,
204+ ) ;
191205 }
192206 // TODO: flush if serverless (first extract function)
193207 } ,
You can’t perform that action at this time.
0 commit comments