1
1
import {
2
+ captureException ,
2
3
debug ,
3
4
flushIfServerless ,
4
5
getDefaultIsolationScope ,
5
6
getIsolationScope ,
7
+ SEMANTIC_ATTRIBUTE_SENTRY_OP ,
8
+ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
6
9
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
7
10
SPAN_STATUS_ERROR ,
8
11
SPAN_STATUS_OK ,
@@ -23,18 +26,18 @@ export function instrumentMiddlewareHandler(handler: EventHandler, fileName: str
23
26
24
27
debug . log ( `Sentry middleware: ${ fileName } handling ${ middlewarePath } ` ) ;
25
28
29
+ const origin = 'auto.http.nuxt' ;
26
30
const isolationScope = getIsolationScope ( ) ;
27
31
const newIsolationScope = isolationScope === getDefaultIsolationScope ( ) ? isolationScope . clone ( ) : isolationScope ;
28
32
29
33
return withIsolationScope ( newIsolationScope , async ( ) => {
30
34
return startSpan (
31
35
{
32
- name : `middleware.${ fileName } ` ,
33
- op : 'middleware.nitro' ,
36
+ name : `${ fileName } ` ,
34
37
attributes : {
35
- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom ' ,
36
- 'middleware.name' : fileName ,
37
- 'middleware.path' : middlewarePath ,
38
+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'http.server.middleware ' ,
39
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
40
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : origin ,
38
41
} ,
39
42
} ,
40
43
async span => {
@@ -45,6 +48,15 @@ export function instrumentMiddlewareHandler(handler: EventHandler, fileName: str
45
48
} catch ( error ) {
46
49
span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'internal_error' } ) ;
47
50
span . recordException ( error ) ;
51
+ captureException ( error , {
52
+ mechanism : {
53
+ handled : false ,
54
+ type : origin ,
55
+ } ,
56
+ } ) ;
57
+
58
+ span . end ( ) ;
59
+ // Re-throw the error to be handled by the caller
48
60
throw error ;
49
61
} finally {
50
62
await flushIfServerless ( ) ;
0 commit comments