Skip to content

Commit c345104

Browse files
committed
fix: set paramaterized route path attributes
1 parent f9ed00d commit c345104

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

packages/nitro/src/runtime/hooks/captureTracingEvents.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ function setupH3TracingChannels(): void {
114114
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: data?.type === 'middleware' ? 'middleware.nitro' : 'http.server',
115115
},
116116
},
117-
s => s,
117+
span => {
118+
setParameterizedRouteAttributes(span, data.event);
119+
120+
return span;
121+
},
118122
);
119123
});
120124

@@ -242,3 +246,35 @@ function setupSrvxTracingChannels(): void {
242246
error: onTraceError,
243247
});
244248
}
249+
250+
/**
251+
* Sets the parameterized route attributes on the span.
252+
*/
253+
function setParameterizedRouteAttributes(span: Span, event: H3TracingRequestEvent['event']): void {
254+
const rootSpan = getRootSpan(span);
255+
if (!rootSpan) {
256+
return;
257+
}
258+
259+
const matchedRoutePath = getParameterizedRoute(event);
260+
if (!matchedRoutePath) {
261+
return;
262+
}
263+
264+
rootSpan.setAttributes({
265+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
266+
'http.route': matchedRoutePath,
267+
});
268+
269+
const params = event.context?.params;
270+
271+
if (params && typeof params === 'object') {
272+
Object.entries(params).forEach(([key, value]) => {
273+
// Based on this convention: https://getsentry.github.io/sentry-conventions/generated/attributes/url.html#urlpathparameterkey
274+
rootSpan.setAttributes({
275+
[`url.path.parameter.${key}`]: String(value),
276+
[`params.${key}`]: String(value),
277+
});
278+
});
279+
}
280+
}

0 commit comments

Comments
 (0)