Skip to content

Commit cafd864

Browse files
committed
fix: capture exceptions at the span level
1 parent b459f93 commit cafd864

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/nuxt/src/runtime/hooks/instrumentMiddlewareHandler.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {
2+
captureException,
23
debug,
34
flushIfServerless,
45
getDefaultIsolationScope,
56
getIsolationScope,
7+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
8+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
69
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
710
SPAN_STATUS_ERROR,
811
SPAN_STATUS_OK,
@@ -23,18 +26,18 @@ export function instrumentMiddlewareHandler(handler: EventHandler, fileName: str
2326

2427
debug.log(`Sentry middleware: ${fileName} handling ${middlewarePath}`);
2528

29+
const origin = 'auto.http.nuxt';
2630
const isolationScope = getIsolationScope();
2731
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
2832

2933
return withIsolationScope(newIsolationScope, async () => {
3034
return startSpan(
3135
{
32-
name: `middleware.${fileName}`,
33-
op: 'middleware.nitro',
36+
name: `${fileName}`,
3437
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,
3841
},
3942
},
4043
async span => {
@@ -45,6 +48,15 @@ export function instrumentMiddlewareHandler(handler: EventHandler, fileName: str
4548
} catch (error) {
4649
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
4750
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
4860
throw error;
4961
} finally {
5062
await flushIfServerless();

0 commit comments

Comments
 (0)