From 383743a8e7150d6f68913b439c3eba8c5cf8874d Mon Sep 17 00:00:00 2001 From: Andrei <168741329+andreiborza@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:22:38 +0200 Subject: [PATCH] fix(solidstart): Set proper sentry origin for solid router integration when used in solidstart sdk (#12919) The `@sentry/solid/solidrouter` integration is used within the solid start sdk as well, so we need a way to update the `sentry.origin` for navigation spans to be for the correct framework. I opted to read this out of the sdk metadata instead of exposing extra api surface and passing it through several levels. --- .../solidstart/tests/performance.client.test.ts | 6 +++--- packages/solid/src/solidrouter.ts | 9 ++++++++- packages/solid/test/solidrouter.test.tsx | 5 +++++ packages/solidstart/test/client/solidrouter.test.tsx | 9 +++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/solidstart/tests/performance.client.test.ts b/dev-packages/e2e-tests/test-applications/solidstart/tests/performance.client.test.ts index 17e57ba47d8d..6e5f43e016c8 100644 --- a/dev-packages/e2e-tests/test-applications/solidstart/tests/performance.client.test.ts +++ b/dev-packages/e2e-tests/test-applications/solidstart/tests/performance.client.test.ts @@ -36,7 +36,7 @@ test('sends a navigation transaction', async ({ page }) => { contexts: { trace: { op: 'navigation', - origin: 'auto.navigation.solid.solidrouter', + origin: 'auto.navigation.solidstart.solidrouter', }, }, transaction: '/users/5', @@ -62,7 +62,7 @@ test('updates the transaction when using the back button', async ({ page }) => { contexts: { trace: { op: 'navigation', - origin: 'auto.navigation.solid.solidrouter', + origin: 'auto.navigation.solidstart.solidrouter', }, }, transaction: '/users/6', @@ -82,7 +82,7 @@ test('updates the transaction when using the back button', async ({ page }) => { contexts: { trace: { op: 'navigation', - origin: 'auto.navigation.solid.solidrouter', + origin: 'auto.navigation.solidstart.solidrouter', }, }, transaction: '/', diff --git a/packages/solid/src/solidrouter.ts b/packages/solid/src/solidrouter.ts index 2f343cfe9d7c..da0391dea35e 100644 --- a/packages/solid/src/solidrouter.ts +++ b/packages/solid/src/solidrouter.ts @@ -33,11 +33,18 @@ function handleNavigation(location: string): void { return; } + // The solid router integration will be used for both solid and solid start. + // To avoid increasing the api surface with internal properties, we look at + // the sdk metadata. + const metaData = client.getSdkMetadata(); + const { name } = (metaData && metaData.sdk) || {}; + const framework = name && name.includes('solidstart') ? 'solidstart' : 'solid'; + startBrowserTracingNavigationSpan(client, { name: location, attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation', - [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solid.solidrouter', + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.${framework}.solidrouter`, [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, }); diff --git a/packages/solid/test/solidrouter.test.tsx b/packages/solid/test/solidrouter.test.tsx index 029b90794b70..44268e6716ab 100644 --- a/packages/solid/test/solidrouter.test.tsx +++ b/packages/solid/test/solidrouter.test.tsx @@ -44,6 +44,11 @@ describe('solidRouterBrowserTracingIntegration', () => { tracesSampleRate: 1, transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => Promise.resolve({})), stackParser: () => [], + _metadata: { + sdk: { + name: 'sentry.javascript.solid', + }, + }, }); } diff --git a/packages/solidstart/test/client/solidrouter.test.tsx b/packages/solidstart/test/client/solidrouter.test.tsx index d6b161c3a7d9..681b8d7b5ce7 100644 --- a/packages/solidstart/test/client/solidrouter.test.tsx +++ b/packages/solidstart/test/client/solidrouter.test.tsx @@ -44,6 +44,11 @@ describe('solidRouterBrowserTracingIntegration', () => { tracesSampleRate: 1, transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => Promise.resolve({})), stackParser: () => [], + _metadata: { + sdk: { + name: 'sentry.javascript.solidstart', + }, + }, }); } @@ -138,7 +143,7 @@ describe('solidRouterBrowserTracingIntegration', () => { data: expect.objectContaining({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation', - [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solid.solidrouter', + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solidstart.solidrouter', }), }), ); @@ -170,7 +175,7 @@ describe('solidRouterBrowserTracingIntegration', () => { data: expect.objectContaining({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation', - [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solid.solidrouter', + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solidstart.solidrouter', }), }), );