Skip to content

Commit bb8a6bf

Browse files
committed
update url parsing
1 parent 8fa1fbf commit bb8a6bf

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

packages/react-router/src/server/wrapServerAction.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { SpanAttributes } from '@sentry/core';
22
import {
33
getActiveSpan,
44
getRootSpan,
5+
parseStringToURLObject,
56
SEMANTIC_ATTRIBUTE_SENTRY_OP,
67
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
78
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -43,20 +44,16 @@ export function wrapServerAction<T>(options: SpanOptions = {}, actionFn: (args:
4344
const root = getRootSpan(active);
4445
// coming from auto.http.otel.http
4546
if (spanToJSON(root).description === 'POST') {
46-
let pathname;
47-
try {
48-
pathname = new URL(args.request.url).pathname;
49-
} catch (error) {
50-
// let's not do anything in case the url parsing fails
51-
return actionFn(args);
47+
const url = parseStringToURLObject(args.request.url);
48+
if (url?.pathname) {
49+
root.setAttributes({
50+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
51+
[SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE]: `${args.request.method} ${url.pathname}`,
52+
});
5253
}
53-
root.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE, args.request.url);
54-
root.setAttributes({
55-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
56-
[SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE]: `${args.request.method} ${pathname}`,
57-
});
5854
}
5955
}
56+
6057
return startSpan(
6158
{
6259
name,

packages/react-router/src/server/wrapServerLoader.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { SpanAttributes } from '@sentry/core';
22
import {
33
getActiveSpan,
44
getRootSpan,
5+
parseStringToURLObject,
56
SEMANTIC_ATTRIBUTE_SENTRY_OP,
67
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
78
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -43,18 +44,14 @@ export function wrapServerLoader<T>(options: SpanOptions = {}, loaderFn: (args:
4344
const root = getRootSpan(active);
4445
// coming from auto.http.otel.http
4546
if (spanToJSON(root).description === 'GET') {
46-
let pathname;
47-
try {
48-
pathname = new URL(args.request.url).pathname;
49-
} catch (error) {
50-
// let's not do anything in case the url parsing fails
51-
return loaderFn(args);
47+
const url = parseStringToURLObject(args.request.url);
48+
49+
if (url?.pathname) {
50+
root.setAttributes({
51+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
52+
[SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE]: `${args.request.method} ${url.pathname}`,
53+
});
5254
}
53-
root.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE, args.request.url);
54-
root.setAttributes({
55-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
56-
[SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE]: `${args.request.method} ${pathname}`,
57-
});
5855
}
5956
}
6057
return startSpan(

0 commit comments

Comments
 (0)