11import {
22 captureException ,
3- flushIfServerless ,
3+ flush ,
44 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
55 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
66 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
@@ -74,6 +74,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
7474 const [ event , env , context ] = args ;
7575 return withIsolationScope ( isolationScope => {
7676 const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
77+ const waitUntil = context . waitUntil . bind ( context ) ;
7778
7879 const client = init ( { ...options , ctx : context } ) ;
7980 isolationScope . setClient ( client ) ;
@@ -99,7 +100,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
99100 captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
100101 throw e ;
101102 } finally {
102- await flushIfServerless ( { cloudflareCtx : context } ) ;
103+ waitUntil ( flush ( 2000 ) ) ;
103104 }
104105 } ,
105106 ) ;
@@ -116,6 +117,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
116117 const [ emailMessage , env , context ] = args ;
117118 return withIsolationScope ( isolationScope => {
118119 const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
120+ const waitUntil = context . waitUntil . bind ( context ) ;
119121
120122 const client = init ( { ...options , ctx : context } ) ;
121123 isolationScope . setClient ( client ) ;
@@ -139,7 +141,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
139141 captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
140142 throw e ;
141143 } finally {
142- await flushIfServerless ( { cloudflareCtx : context } ) ;
144+ waitUntil ( flush ( 2000 ) ) ;
143145 }
144146 } ,
145147 ) ;
@@ -157,6 +159,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
157159
158160 return withIsolationScope ( isolationScope => {
159161 const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
162+ const waitUntil = context . waitUntil . bind ( context ) ;
160163
161164 const client = init ( { ...options , ctx : context } ) ;
162165 isolationScope . setClient ( client ) ;
@@ -188,7 +191,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
188191 captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
189192 throw e ;
190193 } finally {
191- await flushIfServerless ( { cloudflareCtx : context } ) ;
194+ waitUntil ( flush ( 2000 ) ) ;
192195 }
193196 } ,
194197 ) ;
@@ -207,6 +210,8 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
207210 return withIsolationScope ( async isolationScope => {
208211 const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
209212
213+ const waitUntil = context . waitUntil . bind ( context ) ;
214+
210215 const client = init ( { ...options , ctx : context } ) ;
211216 isolationScope . setClient ( client ) ;
212217
@@ -218,7 +223,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
218223 captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
219224 throw e ;
220225 } finally {
221- await flushIfServerless ( { cloudflareCtx : context } ) ;
226+ waitUntil ( flush ( 2000 ) ) ;
222227 }
223228 } ) ;
224229 } ,
0 commit comments