-
-
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.
ref(core): Use versioned carrier on global object (#12206)
This PR implements a versioned Sentry carrier as described in #12188. The idea is that SDKs can from now on access their global Sentry instance and thereby no longer overwrite or interfere with potentially other SDKs (e.g. 3rd party libraries, scripts, etc). Internally, SDKs can access their carrier via the `window.__SENTRY__[SDK_VERSION]`. Externally (spotlight, loader script) via `window.__SENTRY__[window.__SENTRY__.version]`. --------- Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
- Loading branch information
Showing
24 changed files
with
411 additions
and
90 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
19 changes: 19 additions & 0 deletions
19
dev-packages/browser-integration-tests/suites/old-sdk-interop/acs/getCurrentScope/init.js
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
/** | ||
* This simulates an relatively new v7 SDK setting acs on the __SENTRY__ carrier. | ||
* see: https://github.com/getsentry/sentry-javascript/issues/12054 | ||
*/ | ||
window.__SENTRY__ = { | ||
acs: { | ||
getCurrentScope: () => { | ||
return 'scope'; | ||
}, | ||
}, | ||
}; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
}); |
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/old-sdk-interop/acs/getCurrentScope/subject.js
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const sentryCarrier = window && window.__SENTRY__; | ||
|
||
/** | ||
* Simulate an old pre v8 SDK obtaining the hub from the global sentry carrier | ||
* and checking for the hub version. | ||
*/ | ||
const res = sentryCarrier.acs && sentryCarrier.acs.getCurrentScope(); | ||
|
||
// Write back result into the document | ||
document.getElementById('currentScope').innerText = res && 'scope'; |
9 changes: 9 additions & 0 deletions
9
...ckages/browser-integration-tests/suites/old-sdk-interop/acs/getCurrentScope/template.html
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<p id="currentScope"></p> | ||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
dev-packages/browser-integration-tests/suites/old-sdk-interop/acs/getCurrentScope/test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
|
||
sentryTest( | ||
"doesn't crash if older SDKs access `acs.getCurrentScope` on the global object", | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
await expect(page.locator('#currentScope')).toHaveText('scope'); | ||
}, | ||
); |
19 changes: 19 additions & 0 deletions
19
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/isOlderThan/init.js
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
/** | ||
* This simulates an old, pre-v8 SDK setting itself up on the global __SENTRY__ carrier. | ||
* see: https://github.com/getsentry/sentry-javascript/issues/12155 | ||
*/ | ||
window.__SENTRY__ = { | ||
hub: { | ||
isOlderThan: version => { | ||
return version < 7; | ||
}, | ||
}, | ||
}; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
}); |
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/isOlderThan/subject.js
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const sentryCarrier = window && window.__SENTRY__; | ||
|
||
/** | ||
* Simulate an old pre v8 SDK obtaining the hub from the global sentry carrier | ||
* and checking for the hub version. | ||
*/ | ||
const res = sentryCarrier.hub && sentryCarrier.hub.isOlderThan(7); | ||
|
||
// Write back result into the document | ||
document.getElementById('olderThan').innerText = res; |
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/isOlderThan/template.html
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<p id="olderThan"></p> | ||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/isOlderThan/test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
|
||
sentryTest( | ||
"doesn't crash if older SDKs access `hub.isOlderThan` on the global object", | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
await expect(page.locator('#olderThan')).toHaveText('false'); | ||
}, | ||
); |
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
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
Oops, something went wrong.