-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Ensure builtin stack frames don't affect thirdPartyErrorFilterIntegration
#17693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
dev-packages/browser-integration-tests/suites/integrations/thirdPartyErrorsFilter/init.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
// eslint-disable-next-line import/no-duplicates | ||
import { thirdPartyErrorFilterIntegration } from '@sentry/browser'; | ||
// eslint-disable-next-line import/no-duplicates | ||
import { captureConsoleIntegration } from '@sentry/browser'; | ||
|
||
// This is the code the bundler plugin would inject to mark the init bundle as a first party module: | ||
var _sentryModuleMetadataGlobal = | ||
typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: typeof self !== 'undefined' | ||
? self | ||
: {}; | ||
|
||
_sentryModuleMetadataGlobal._sentryModuleMetadata = _sentryModuleMetadataGlobal._sentryModuleMetadata || {}; | ||
|
||
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack] = Object.assign( | ||
{}, | ||
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack], | ||
{ | ||
'_sentryBundlerPluginAppKey:my-app': true, | ||
}, | ||
); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [ | ||
thirdPartyErrorFilterIntegration({ behaviour: 'apply-tag-if-contains-third-party-frames', filterKeys: ['my-app'] }), | ||
captureConsoleIntegration({ levels: ['error'], handled: false }), | ||
], | ||
attachStacktrace: true, | ||
}); |
28 changes: 28 additions & 0 deletions
28
dev-packages/browser-integration-tests/suites/integrations/thirdPartyErrorsFilter/subject.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This is the code the bundler plugin would inject to mark the subject bundle as a first party module: | ||
var _sentryModuleMetadataGlobal = | ||
typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: typeof self !== 'undefined' | ||
? self | ||
: {}; | ||
|
||
_sentryModuleMetadataGlobal._sentryModuleMetadata = _sentryModuleMetadataGlobal._sentryModuleMetadata || {}; | ||
|
||
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack] = Object.assign( | ||
{}, | ||
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack], | ||
{ | ||
'_sentryBundlerPluginAppKey:my-app': true, | ||
}, | ||
); | ||
|
||
const errorBtn = document.getElementById('errBtn'); | ||
errorBtn.addEventListener('click', async () => { | ||
Promise.allSettled([Promise.reject('I am a first party Error')]).then(values => | ||
values.forEach(value => { | ||
if (value.status === 'rejected') console.error(value.reason); | ||
}), | ||
); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...ckages/browser-integration-tests/suites/integrations/thirdPartyErrorsFilter/template.html
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<script src="thirdPartyScript.js"></script> | ||
<button id="errBtn">Throw 1st part yerror</button> | ||
</body> | ||
</html> |
75 changes: 75 additions & 0 deletions
75
dev-packages/browser-integration-tests/suites/integrations/thirdPartyErrorsFilter/test.ts
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { expect } from '@playwright/test'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser, waitForErrorRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest('tags event if contains at least one third-party frame', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const errorEventPromise = waitForErrorRequest(page, e => { | ||
return e.exception?.values?.[0]?.value === 'I am a third party Error'; | ||
}); | ||
|
||
await page.route('**/thirdPartyScript.js', route => | ||
route.fulfill({ | ||
status: 200, | ||
body: readFileSync(join(__dirname, 'thirdPartyScript.js')), | ||
}), | ||
); | ||
|
||
await page.goto(url); | ||
|
||
const errorEvent = envelopeRequestParser(await errorEventPromise); | ||
expect(errorEvent.tags?.third_party_code).toBe(true); | ||
}); | ||
|
||
/** | ||
* This test seems a bit more complicated than necessary but this is intentional: | ||
* When using `captureConsoleIntegration` in combination with `thirdPartyErrorFilterIntegration` | ||
* and `attachStacktrace: true`, the stack trace includes native code stack frames which previously broke | ||
* the third party error filtering logic. | ||
* | ||
* see https://github.com/getsentry/sentry-javascript/issues/17674 | ||
*/ | ||
sentryTest( | ||
"doesn't tag event if doesn't contain third-party frames", | ||
async ({ getLocalTestUrl, page, browserName }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const errorEventPromise = waitForErrorRequest(page, e => { | ||
return e.exception?.values?.[0]?.value === 'I am a first party Error'; | ||
}); | ||
|
||
await page.route('**/thirdPartyScript.js', route => | ||
route.fulfill({ | ||
status: 200, | ||
body: readFileSync(join(__dirname, 'thirdPartyScript.js')), | ||
}), | ||
); | ||
|
||
await page.goto(url); | ||
|
||
await page.click('#errBtn'); | ||
|
||
const errorEvent = envelopeRequestParser(await errorEventPromise); | ||
|
||
expect(errorEvent.tags?.third_party_code).toBeUndefined(); | ||
|
||
// ensure the stack trace includes native code stack frames which previously broke | ||
// the third party error filtering logic | ||
if (browserName === 'chromium') { | ||
expect(errorEvent.exception?.values?.[0]?.stacktrace?.frames).toContainEqual({ | ||
filename: '<anonymous>', | ||
function: 'Array.forEach', | ||
in_app: true, | ||
}); | ||
} else if (browserName === 'webkit') { | ||
expect(errorEvent.exception?.values?.[0]?.stacktrace?.frames).toContainEqual({ | ||
filename: '[native code]', | ||
function: 'forEach', | ||
in_app: true, | ||
}); | ||
} | ||
}, | ||
); |
3 changes: 3 additions & 0 deletions
3
.../browser-integration-tests/suites/integrations/thirdPartyErrorsFilter/thirdPartyScript.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
setTimeout(() => { | ||
throw new Error('I am a third party Error'); | ||
}, 100); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.