Skip to content

Commit

Permalink
fix(solidstart): Set proper sentry origin for solid router integratio…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
andreiborza authored Jul 15, 2024
1 parent 1d3e208 commit 383743a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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: '/',
Expand Down
9 changes: 8 additions & 1 deletion packages/solid/src/solidrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
Expand Down
5 changes: 5 additions & 0 deletions packages/solid/test/solidrouter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe('solidRouterBrowserTracingIntegration', () => {
tracesSampleRate: 1,
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => Promise.resolve({})),
stackParser: () => [],
_metadata: {
sdk: {
name: 'sentry.javascript.solid',
},
},
});
}

Expand Down
9 changes: 7 additions & 2 deletions packages/solidstart/test/client/solidrouter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe('solidRouterBrowserTracingIntegration', () => {
tracesSampleRate: 1,
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => Promise.resolve({})),
stackParser: () => [],
_metadata: {
sdk: {
name: 'sentry.javascript.solidstart',
},
},
});
}

Expand Down Expand Up @@ -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',
}),
}),
);
Expand Down Expand Up @@ -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',
}),
}),
);
Expand Down

0 comments on commit 383743a

Please sign in to comment.