Skip to content

Commit 3ac42f7

Browse files
authored
fix(nuxt): Do not drop parametrized routes (#17357)
I just found out Nuxt is dropping spans for catch-all routes. related to #16843 (as we have parametrized routes since then)
1 parent ca4fba6 commit 3ac42f7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/nuxt/src/server/sdk.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export function lowQualityTransactionsFilter(options: SentryNuxtServerOptions):
4343
if (event.type !== 'transaction' || !event.transaction) {
4444
return event;
4545
}
46+
47+
// Check if this looks like a parametrized route (contains :param or :param() patterns)
48+
const hasRouteParameters = /\/:[^(/\s]*(\([^)]*\))?[^/\s]*/.test(event.transaction);
49+
50+
if (hasRouteParameters) {
51+
return event;
52+
}
53+
4654
// We don't want to send transaction for file requests, so everything ending with a *.someExtension should be filtered out
4755
// path.extname will return an empty string for normal page requests
4856
if (path.extname(event.transaction)) {

packages/nuxt/test/server/sdk.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Nuxt Server SDK', () => {
4242
expect(init({})).not.toBeUndefined();
4343
});
4444

45-
describe('low quality transactions filter (%s)', () => {
45+
describe('lowQualityTransactionsFilter (%s)', () => {
4646
const beforeSendEvent = vi.fn(event => event);
4747
const client = init({
4848
dsn: 'https://[email protected]/1337',
@@ -63,7 +63,8 @@ describe('Nuxt Server SDK', () => {
6363
expect(beforeSendEvent).not.toHaveBeenCalled();
6464
});
6565

66-
it.each(['GET /', 'POST /_server'])(
66+
// Nuxt parametrizes routes sometimes in a special way - especially catchAll o.O
67+
it.each(['GET /', 'POST /_server', 'GET /catchAll/:id(.*)*', 'GET /article/:slug()', 'GET /user/:id'])(
6768
'does not filter out high quality or route transactions (%s)',
6869
async transaction => {
6970
client.captureEvent({ type: 'transaction', transaction });

0 commit comments

Comments
 (0)