diff --git a/packages/bun/src/integrations/bunserver.ts b/packages/bun/src/integrations/bunserver.ts index d6fd4650e7cb..7d875cfdfbbe 100644 --- a/packages/bun/src/integrations/bunserver.ts +++ b/packages/bun/src/integrations/bunserver.ts @@ -294,7 +294,9 @@ function getSpanAttributesFromParsedUrl( attributes[URL_PORT] = parsedUrl.port; } if (parsedUrl.protocol) { - attributes[URL_SCHEME] = parsedUrl.protocol; + // URL.protocol includes a trailing colon (e.g. 'https:') but the OTel + // url.scheme attribute must not (e.g. 'https'). + attributes[URL_SCHEME] = parsedUrl.protocol.replace(':', ''); } if (parsedUrl.hostname) { attributes[URL_DOMAIN] = parsedUrl.hostname; diff --git a/packages/bun/test/integrations/bunserver.test.ts b/packages/bun/test/integrations/bunserver.test.ts index 775de5236c55..e0dbb5b270d9 100644 --- a/packages/bun/test/integrations/bunserver.test.ts +++ b/packages/bun/test/integrations/bunserver.test.ts @@ -52,7 +52,7 @@ describe('Bun Serve Integration', () => { 'url.path': '/users', 'url.full': `http://localhost:${port}/users?id=123`, 'url.port': port.toString(), - 'url.scheme': 'http:', + 'url.scheme': 'http', 'url.domain': 'localhost', 'http.request.header.accept': '*/*', 'http.request.header.accept_encoding': 'gzip, deflate, br, zstd', @@ -95,7 +95,7 @@ describe('Bun Serve Integration', () => { 'url.path': '/', 'url.full': `http://localhost:${port}/`, 'url.port': port.toString(), - 'url.scheme': 'http:', + 'url.scheme': 'http', 'url.domain': 'localhost', 'http.request.header.accept': '*/*', 'http.request.header.accept_encoding': 'gzip, deflate, br, zstd', @@ -184,7 +184,7 @@ describe('Bun Serve Integration', () => { 'url.path': '/api/test', 'url.full': `http://localhost:${port}/api/test`, 'url.port': port.toString(), - 'url.scheme': 'http:', + 'url.scheme': 'http', 'url.domain': 'localhost', // HTTP headers as span attributes following OpenTelemetry semantic conventions 'http.request.header.user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', @@ -261,7 +261,7 @@ describe('Bun Serve Integration', () => { 'url.path': '/users/123', 'url.full': `http://localhost:${port}/users/123`, 'url.port': port.toString(), - 'url.scheme': 'http:', + 'url.scheme': 'http', 'url.domain': 'localhost', }), op: 'http.server', @@ -299,7 +299,7 @@ describe('Bun Serve Integration', () => { 'url.path': '/api/users/123', 'url.full': `http://localhost:${port}/api/users/123`, 'url.port': port.toString(), - 'url.scheme': 'http:', + 'url.scheme': 'http', 'url.domain': 'localhost', }), op: 'http.server', diff --git a/packages/core/src/utils/url.ts b/packages/core/src/utils/url.ts index 6f88f390b0f7..fbeaa6d052dd 100644 --- a/packages/core/src/utils/url.ts +++ b/packages/core/src/utils/url.ts @@ -226,7 +226,9 @@ export function getHttpSpanDetailsFromUrlObject( attributes[URL_PORT] = urlObject.port; } if (urlObject.protocol) { - attributes[URL_SCHEME] = urlObject.protocol; + // URL.protocol includes a trailing colon (e.g. 'https:') but the OTel + // url.scheme attribute must not (e.g. 'https'). + attributes[URL_SCHEME] = urlObject.protocol.replace(':', ''); } if (urlObject.hostname) { attributes[kind === 'server' ? SERVER_ADDRESS : URL_DOMAIN] = urlObject.hostname; diff --git a/packages/core/test/lib/utils/url.test.ts b/packages/core/test/lib/utils/url.test.ts index 9f42966b5625..8affc2f81c07 100644 --- a/packages/core/test/lib/utils/url.test.ts +++ b/packages/core/test/lib/utils/url.test.ts @@ -460,7 +460,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.fragment': 'section', 'url.full': 'https://example.com/api/users?q=test#section', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', }); }); @@ -474,7 +474,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://example.com/api/users', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'http.request.method': 'POST', }); }); @@ -495,7 +495,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://example.com/api/users', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'http.route': '/api/users/:id', }); }); @@ -510,7 +510,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/', 'url.full': 'https://example.com/', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', }); }); @@ -524,7 +524,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://example.com:8080/api/users', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'url.port': '8080', }); }); @@ -539,7 +539,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://example.com:3000/api/users', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'url.port': '3000', 'http.request.method': 'PUT', }); @@ -561,7 +561,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users/123', 'url.full': 'https://example.com/api/users/123', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'http.route': '/api/users/:id', 'http.request.method': 'PATCH', }); @@ -584,7 +584,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.query': 'q=test&page=1', 'url.full': 'https://example.com/api/search?q=test&page=1', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'http.route': '/api/search', }); }); @@ -606,7 +606,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.fragment': 'section-1', 'url.full': 'https://example.com/api/docs#section-1', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'http.route': '/api/docs', }); }); @@ -621,7 +621,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://user:pass@example.com/api/users', 'server.address': 'example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', }); }); @@ -635,7 +635,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://192.168.1.1:8080/api/users', 'server.address': '192.168.1.1', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'url.port': '8080', }); }); @@ -650,7 +650,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/api/users', 'url.full': 'https://[2001:db8::1]:8080/api/users', 'server.address': '[2001:db8::1]', - 'url.scheme': 'https:', + 'url.scheme': 'https', 'url.port': '8080', }); }); @@ -665,7 +665,7 @@ describe('getHttpSpanDetailsFromUrlObject', () => { 'url.path': '/users', 'url.full': 'https://api.example.com/users', 'server.address': 'api.example.com', - 'url.scheme': 'https:', + 'url.scheme': 'https', }); }); }); diff --git a/packages/react-router/src/vite/makeCustomSentryVitePlugins.ts b/packages/react-router/src/vite/makeCustomSentryVitePlugins.ts index b2d41378db33..196ea04728e0 100644 --- a/packages/react-router/src/vite/makeCustomSentryVitePlugins.ts +++ b/packages/react-router/src/vite/makeCustomSentryVitePlugins.ts @@ -19,6 +19,11 @@ export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuil release, } = options; + // Destructure keys that are merged explicitly below so the trailing spread + // cannot overwrite them with the user's raw value. + const { sourcemaps: userSourcemaps, ...restUnstableVitePluginOptions } = + unstable_sentryVitePluginOptions ?? {}; + const sentryVitePlugins = sentryVitePlugin({ applicationKey, authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, @@ -45,9 +50,9 @@ export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuil // will be handled in buildEnd hook sourcemaps: { disable: true, - ...unstable_sentryVitePluginOptions?.sourcemaps, + ...userSourcemaps, }, - ...unstable_sentryVitePluginOptions, + ...restUnstableVitePluginOptions, }) as Plugin[]; return sentryVitePlugins;