1
1
import {
2
2
captureException ,
3
- flush ,
4
3
SEMANTIC_ATTRIBUTE_SENTRY_OP ,
5
4
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
6
5
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
7
6
startSpan ,
8
7
withIsolationScope ,
9
8
} from '@sentry/core' ;
9
+ import { flushIfServerless } from '@sentry/core/src' ;
10
10
import { setAsyncLocalStorageAsyncContextStrategy } from './async' ;
11
11
import type { CloudflareOptions } from './client' ;
12
12
import { isInstrumented , markAsInstrumented } from './instrument' ;
@@ -74,7 +74,6 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
74
74
const [ event , env , context ] = args ;
75
75
return withIsolationScope ( isolationScope => {
76
76
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
77
- const waitUntil = context . waitUntil . bind ( context ) ;
78
77
79
78
const client = init ( { ...options , ctx : context } ) ;
80
79
isolationScope . setClient ( client ) ;
@@ -100,7 +99,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
100
99
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
101
100
throw e ;
102
101
} finally {
103
- waitUntil ( flush ( 2000 ) ) ;
102
+ await flushIfServerless ( { cloudflareCtx : context } ) ;
104
103
}
105
104
} ,
106
105
) ;
@@ -117,7 +116,6 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
117
116
const [ emailMessage , env , context ] = args ;
118
117
return withIsolationScope ( isolationScope => {
119
118
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
120
- const waitUntil = context . waitUntil . bind ( context ) ;
121
119
122
120
const client = init ( { ...options , ctx : context } ) ;
123
121
isolationScope . setClient ( client ) ;
@@ -141,7 +139,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
141
139
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
142
140
throw e ;
143
141
} finally {
144
- waitUntil ( flush ( 2000 ) ) ;
142
+ await flushIfServerless ( { cloudflareCtx : context } ) ;
145
143
}
146
144
} ,
147
145
) ;
@@ -159,7 +157,6 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
159
157
160
158
return withIsolationScope ( isolationScope => {
161
159
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
162
- const waitUntil = context . waitUntil . bind ( context ) ;
163
160
164
161
const client = init ( { ...options , ctx : context } ) ;
165
162
isolationScope . setClient ( client ) ;
@@ -191,7 +188,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
191
188
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
192
189
throw e ;
193
190
} finally {
194
- waitUntil ( flush ( 2000 ) ) ;
191
+ await flushIfServerless ( { cloudflareCtx : context } ) ;
195
192
}
196
193
} ,
197
194
) ;
@@ -210,8 +207,6 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
210
207
return withIsolationScope ( async isolationScope => {
211
208
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
212
209
213
- const waitUntil = context . waitUntil . bind ( context ) ;
214
-
215
210
const client = init ( { ...options , ctx : context } ) ;
216
211
isolationScope . setClient ( client ) ;
217
212
@@ -223,7 +218,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
223
218
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
224
219
throw e ;
225
220
} finally {
226
- waitUntil ( flush ( 2000 ) ) ;
221
+ await flushIfServerless ( { cloudflareCtx : context } ) ;
227
222
}
228
223
} ) ;
229
224
} ,
0 commit comments