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 ,
9
8
} from '@sentry/core' ;
10
9
import { setAsyncLocalStorageAsyncContextStrategy } from './async' ;
11
10
import type { CloudflareOptions } from './client' ;
11
+ import { makeFlushAfterAll } from './flush' ;
12
12
import { isInstrumented , markAsInstrumented } from './instrument' ;
13
13
import { getFinalOptions } from './options' ;
14
14
import { wrapRequestHandler } from './request' ;
@@ -72,6 +72,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
72
72
handler . scheduled = new Proxy ( handler . scheduled , {
73
73
apply ( target , thisArg , args : Parameters < ExportedHandlerScheduledHandler < Env > > ) {
74
74
const [ event , env , context ] = args ;
75
+ const flushAfterAll = makeFlushAfterAll ( context ) ;
75
76
return withIsolationScope ( isolationScope => {
76
77
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
77
78
@@ -99,7 +100,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
99
100
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
100
101
throw e ;
101
102
} finally {
102
- context . waitUntil ( flush ( 2000 ) ) ;
103
+ flushAfterAll ( 2000 ) ;
103
104
}
104
105
} ,
105
106
) ;
@@ -114,6 +115,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
114
115
handler . email = new Proxy ( handler . email , {
115
116
apply ( target , thisArg , args : Parameters < EmailExportedHandler < Env > > ) {
116
117
const [ emailMessage , env , context ] = args ;
118
+ const flushAfterAll = makeFlushAfterAll ( context ) ;
117
119
return withIsolationScope ( isolationScope => {
118
120
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
119
121
@@ -139,7 +141,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
139
141
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
140
142
throw e ;
141
143
} finally {
142
- context . waitUntil ( flush ( 2000 ) ) ;
144
+ flushAfterAll ( 2000 ) ;
143
145
}
144
146
} ,
145
147
) ;
@@ -154,6 +156,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
154
156
handler . queue = new Proxy ( handler . queue , {
155
157
apply ( target , thisArg , args : Parameters < ExportedHandlerQueueHandler < Env , QueueHandlerMessage > > ) {
156
158
const [ batch , env , context ] = args ;
159
+ const flushAfterAll = makeFlushAfterAll ( context ) ;
157
160
158
161
return withIsolationScope ( isolationScope => {
159
162
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
@@ -185,7 +188,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
185
188
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
186
189
throw e ;
187
190
} finally {
188
- context . waitUntil ( flush ( 2000 ) ) ;
191
+ flushAfterAll ( 2000 ) ;
189
192
}
190
193
} ,
191
194
) ;
@@ -200,6 +203,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
200
203
handler . tail = new Proxy ( handler . tail , {
201
204
apply ( target , thisArg , args : Parameters < ExportedHandlerTailHandler < Env > > ) {
202
205
const [ , env , context ] = args ;
206
+ const flushAfterAll = makeFlushAfterAll ( context ) ;
203
207
204
208
return withIsolationScope ( async isolationScope => {
205
209
const options = getFinalOptions ( optionsCallback ( env ) , env ) ;
@@ -215,7 +219,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
215
219
captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
216
220
throw e ;
217
221
} finally {
218
- context . waitUntil ( flush ( 2000 ) ) ;
222
+ flushAfterAll ( 2000 ) ;
219
223
}
220
224
} ) ;
221
225
} ,
0 commit comments