File tree 1 file changed +14
-0
lines changed
packages/astro/src/server
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 3
3
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
4
4
captureException ,
5
5
continueTrace ,
6
+ flush ,
6
7
getActiveSpan ,
7
8
getClient ,
8
9
getCurrentScope ,
@@ -14,8 +15,10 @@ import {
14
15
import type { Scope , SpanAttributes } from '@sentry/types' ;
15
16
import {
16
17
addNonEnumerableProperty ,
18
+ logger ,
17
19
objectify ,
18
20
stripUrlQueryAndFragment ,
21
+ vercelWaitUntil ,
19
22
winterCGRequestToRequestData ,
20
23
} from '@sentry/utils' ;
21
24
import type { APIContext , MiddlewareResponseHandler } from 'astro' ;
@@ -188,6 +191,17 @@ async function instrumentRequest(
188
191
} catch ( e ) {
189
192
sendErrorToSentry ( e ) ;
190
193
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
+ ) ;
191
205
}
192
206
// TODO: flush if serverless (first extract function)
193
207
} ,
You can’t perform that action at this time.
0 commit comments