Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/solid/src/solidrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import {
} from '@sentry/conventions/attributes';
import type { Client, Integration, Span } from '@sentry/core';
import {
createCachedRouteProvider,
getClient,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
filterCollectedUrl,
setRouteProvider,
} from '@sentry/core';
import type {
BeforeLeaveEventArgs,
Expand All @@ -36,6 +38,11 @@ import { createComponent } from 'solid-js/web';

const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet<Client>();

// Solid Router only exposes matches through `useCurrentMatches()` inside a component, so there is no
// matcher the integration could call. The provider answers from patterns the router root has already
// reported instead.
const ROUTE_PROVIDER = createCachedRouteProvider();

function locationToSpanUrlAttributes(pathname: string, search: string = '', hash: string = ''): Record<string, string> {
const pathWithSearch = `${pathname}${search}${hash}`;

Expand Down Expand Up @@ -129,6 +136,7 @@ function withSentryRouterRoot(Root: Component<RouteSectionProps>): Component<Rou

if (lastMatch) {
const parametrizedRoute = lastMatch.route.pattern || name;
ROUTE_PROVIDER.record(name, lastMatch.route.pattern);
rootSpan.updateName(parametrizedRoute);
rootSpan.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
Expand Down Expand Up @@ -174,6 +182,10 @@ export function solidRouterBrowserTracingIntegration(

return {
...integration,
setup(client) {
setRouteProvider(ROUTE_PROVIDER, client);
integration.setup?.(client);
},
afterAllSetup(client) {
integration.afterAllSetup(client);

Expand Down
Loading