Skip to content

Commit 75f9a6e

Browse files
author
Luca Forstner
committed
Set http.server.middleware op on middleware spans
1 parent 12a90d1 commit 75f9a6e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/nextjs/src/edge/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { context } from '@opentelemetry/api';
22
import {
3+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
34
applySdkMetadata,
45
getCapturedScopesOnSpan,
56
getCurrentScope,
67
getIsolationScope,
78
getRootSpan,
89
registerSpanErrorInstrumentation,
910
setCapturedScopesOnSpan,
11+
spanToJSON,
1012
} from '@sentry/core';
1113

1214
import { GLOBAL_OBJ } from '@sentry/utils';
@@ -52,8 +54,15 @@ export function init(options: VercelEdgeOptions = {}): void {
5254

5355
const client = vercelEdgeInit(opts);
5456

55-
// Create/fork an isolation whenever we create root spans. This is ok because in Next.js we only create root spans on the edge for incoming requests.
5657
client?.on('spanStart', span => {
58+
const spanAttributes = spanToJSON(span).data;
59+
60+
// Make sure middleware spans get the right op
61+
if (spanAttributes?.['next.span_type'] === 'Middleware.execute') {
62+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'http.server.middleware');
63+
}
64+
65+
// Create/fork an isolation whenever we create root spans. This is ok because in Next.js we only create root spans on the edge for incoming requests.
5766
if (span === getRootSpan(span)) {
5867
const scopes = getCapturedScopesOnSpan(span);
5968

0 commit comments

Comments
 (0)