-
-
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.
feat(nuxt): Add filter for not found source maps (devtools) (#14437)
Dev tools sometimes try to access source maps. This filter makes sure this error is not reported in Sentry as it adds noise to the data.
- Loading branch information
Showing
2 changed files
with
129 additions
and
22 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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import * as SentryNode from '@sentry/node'; | ||
import type { NodeClient } from '@sentry/node'; | ||
import { Scope } from '@sentry/node'; | ||
import { getGlobalScope } from '@sentry/node'; | ||
import { SDK_VERSION } from '@sentry/node'; | ||
import type { EventProcessor } from '@sentry/types'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import type { SentryNuxtServerOptions } from '../../src/common/types'; | ||
import { init } from '../../src/server'; | ||
import { mergeRegisterEsmLoaderHooks } from '../../src/server/sdk'; | ||
import { clientSourceMapErrorFilter, mergeRegisterEsmLoaderHooks } from '../../src/server/sdk'; | ||
|
||
const nodeInit = vi.spyOn(SentryNode, 'init'); | ||
|
||
|
@@ -83,6 +86,88 @@ describe('Nuxt Server SDK', () => { | |
expect.any(Object), | ||
); | ||
}); | ||
|
||
it('registers an event processor', async () => { | ||
let passedEventProcessors: EventProcessor[] = []; | ||
const addEventProcessor = vi | ||
.spyOn(getGlobalScope(), 'addEventProcessor') | ||
.mockImplementation((eventProcessor: EventProcessor) => { | ||
passedEventProcessors = [...passedEventProcessors, eventProcessor]; | ||
return new Scope(); | ||
}); | ||
|
||
init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); | ||
|
||
expect(addEventProcessor).toHaveBeenCalledTimes(2); | ||
expect(passedEventProcessors[0]?.id).toEqual('NuxtLowQualityTransactionsFilter'); | ||
expect(passedEventProcessors[1]?.id).toEqual('NuxtClientSourceMapErrorFilter'); | ||
}); | ||
}); | ||
|
||
describe('clientSourceMapErrorFilter', () => { | ||
const options = { debug: false }; | ||
const filter = clientSourceMapErrorFilter(options); | ||
|
||
describe('filters out errors', () => { | ||
it.each([ | ||
[ | ||
'source map errors with leading /', | ||
{ | ||
exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/_nuxt/file.js.map'" }] }, | ||
}, | ||
], | ||
[ | ||
'source map errors without leading /', | ||
{ exception: { values: [{ value: "ENOENT: no such file or directory, open 'path/to/_nuxt/file.js.map'" }] } }, | ||
], | ||
[ | ||
'source map errors with long path', | ||
{ | ||
exception: { | ||
values: [ | ||
{ | ||
value: | ||
"ENOENT: no such file or directory, open 'path/to/public/_nuxt/public/long/long/path/file.js.map'", | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
])('filters out %s', (_, event) => { | ||
// @ts-expect-error Event type is not correct in tests | ||
expect(filter(event)).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('does not filter out errors', () => { | ||
it.each([ | ||
['other errors', { exception: { values: [{ value: 'Some other error' }] } }], | ||
['events with no exceptions', {}], | ||
[ | ||
'events without _nuxt in path', | ||
{ | ||
exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/other/file.js.map'" }] }, | ||
}, | ||
], | ||
[ | ||
'source map errors with different casing', | ||
{ | ||
exception: { values: [{ value: "ENOENT: No Such file or directory, open '/path/to/_nuxt/file.js.map'" }] }, | ||
}, | ||
], | ||
[ | ||
'non-source-map file', | ||
{ exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/_nuxt/file.js'" }] } }, | ||
], | ||
['events with no exception values', { exception: { values: [] } }], | ||
['events with null exception value', { exception: { values: [null] } }], | ||
])('does not filter out %s', (_, event) => { | ||
// @ts-expect-error Event type is not correct in tests | ||
expect(filter(event)).toEqual(event); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('mergeRegisterEsmLoaderHooks', () => { | ||
|