Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ test('sends a pageload transaction with a route name as transaction name if avai
'sentry.source': 'custom',
'sentry.origin': 'auto.pageload.vue',
'sentry.op': 'pageload',
'navigation.route.id': 'AboutView',
'url.path': '/about',
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/about$/),
},
Expand Down
11 changes: 10 additions & 1 deletion packages/vue/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { captureException, getAbsoluteUrl } from '@sentry/browser';
import { PARAMS_KEY_BASE, URL_PATH_PARAMETER_KEY_BASE, URL_TEMPLATE } from '@sentry/conventions/attributes';
import {
NAVIGATION_ROUTE_ID,
PARAMS_KEY_BASE,
URL_PATH_PARAMETER_KEY_BASE,
URL_TEMPLATE,
} from '@sentry/conventions/attributes';
import type { Span, SpanAttributes, StartSpanOptions, TransactionSource } from '@sentry/core';
import {
getActiveSpan,
Expand Down Expand Up @@ -101,6 +106,10 @@ export function instrumentVueRouter(
attributes[URL_TEMPLATE] = spanName;
}

if (to.name) {
attributes[NAVIGATION_ROUTE_ID] = to.name.toString();
}
Comment on lines +109 to +111

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: When a Vue route name is a Symbol, to.name.toString() incorrectly serializes it to the format "Symbol(routeName)" for the navigation.route.id attribute.
Severity: LOW

Suggested Fix

Before setting the attribute, check if to.name is a Symbol. If it is, use its description property to get a clean identifier. For other types, continue using toString(). For example: const routeId = typeof to.name === 'symbol' ? to.name.description : to.name?.toString(); if (routeId) { attributes[NAVIGATION_ROUTE_ID] = routeId; }.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/vue/src/router.ts#L109-L111

Potential issue: The code at `packages/vue/src/router.ts` sets the `navigation.route.id`
attribute by calling `to.name.toString()`. While Vue Router's type definitions allow a
route's `name` to be a `Symbol`, calling `toString()` on a `Symbol` (e.g.,
`Symbol('about')`) produces a string like `"Symbol(about)"`. This results in a verbose
and likely unintended value for the `navigation.route.id` attribute when developers use
`Symbol`-named routes, which are a supported, albeit uncommon, feature of Vue Router.

Did we get this right? 👍 / 👎 to inform future reviews.


getCurrentScope().setTransactionName(spanName);

// Update the existing page load span with parametrized route information
Expand Down
6 changes: 5 additions & 1 deletion packages/vue/test/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as SentryBrowser from '@sentry/browser';
import type { Span, SpanAttributes } from '@sentry/core';
import * as SentryCore from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { URL_TEMPLATE } from '@sentry/conventions/attributes';
import { NAVIGATION_ROUTE_ID, URL_TEMPLATE } from '@sentry/conventions/attributes';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { Route } from '../src/router';
import { instrumentVueRouter } from '../src/router';
Expand Down Expand Up @@ -465,5 +465,9 @@ function getAttributesForRoute(route: Route, urlTemplate?: string): SpanAttribut
attributes[URL_TEMPLATE] = urlTemplate;
}

if (route.name) {
attributes[NAVIGATION_ROUTE_ID] = route.name.toString();
}

return attributes;
}
Loading