-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nuxt): Avoid sending server resource request transactions (#14497)
Refactor the low quality transaction filter in the Nuxt SDK to filter out all resource requests. Our SDKs should generally not send dedicated transactions for resource requests as they would deplete transaction quota fairly quickly, compared to only tracking page requests.
- Loading branch information
Showing
2 changed files
with
36 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,45 +45,39 @@ describe('Nuxt Server SDK', () => { | |
expect(init({})).not.toBeUndefined(); | ||
}); | ||
|
||
it('filters out low quality transactions', async () => { | ||
describe('low quality transactions filter (%s)', () => { | ||
const beforeSendEvent = vi.fn(event => event); | ||
const client = init({ | ||
dsn: 'https://[email protected]/1337', | ||
}) as NodeClient; | ||
client.on('beforeSendEvent', beforeSendEvent); | ||
|
||
client.captureEvent({ type: 'transaction', transaction: 'GET /' }); | ||
client.captureEvent({ type: 'transaction', transaction: 'GET /_nuxt/some_asset.js' }); | ||
// Although this has the name of the build asset directory (_nuxt), it should not be filtered out as it would not match the regex | ||
client.captureEvent({ type: 'transaction', transaction: 'GET _nuxt/some_asset.js' }); | ||
client.captureEvent({ type: 'transaction', transaction: 'POST /_server' }); | ||
|
||
await client!.flush(); | ||
it.each([ | ||
[ | ||
'GET /_nuxt/some_asset.js', | ||
'GET _nuxt/some_asset.js', | ||
'GET /icons/favicon.ico', | ||
'GET /assets/logo.png', | ||
'GET /icons/zones/forest.svg', | ||
], | ||
])('filters out low quality transactions', async transaction => { | ||
client.captureEvent({ type: 'transaction', transaction }); | ||
await client!.flush(); | ||
expect(beforeSendEvent).not.toHaveBeenCalled(); | ||
}); | ||
|
||
expect(beforeSendEvent).toHaveBeenCalledTimes(3); | ||
expect(beforeSendEvent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transaction: 'GET /', | ||
}), | ||
expect.any(Object), | ||
); | ||
expect(beforeSendEvent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transaction: 'GET _nuxt/some_asset.js', | ||
}), | ||
expect.any(Object), | ||
); | ||
expect(beforeSendEvent).not.toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transaction: 'GET /_nuxt/some_asset.js', | ||
}), | ||
expect.any(Object), | ||
); | ||
expect(beforeSendEvent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transaction: 'POST /_server', | ||
}), | ||
expect.any(Object), | ||
it.each(['GET /', 'POST /_server'])( | ||
'does not filter out high quality or route transactions (%s)', | ||
async transaction => { | ||
client.captureEvent({ type: 'transaction', transaction }); | ||
await client!.flush(); | ||
expect(beforeSendEvent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transaction, | ||
}), | ||
expect.any(Object), | ||
); | ||
}, | ||
); | ||
}); | ||
|
||
|