Skip to content

Commit 9d69b0f

Browse files
author
Luca Forstner
authored
feat(browser): Add __SENTRY_RELEASE__ magic string (#6322)
1 parent 5ba75c7 commit 9d69b0f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

packages/browser/src/sdk.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export const defaultIntegrations = [
3131
new HttpContext(),
3232
];
3333

34+
/**
35+
* A magic string that build tooling can leverage in order to inject a release value into the SDK.
36+
*/
37+
declare const __SENTRY_RELEASE__: string | undefined;
38+
3439
/**
3540
* The Sentry Browser SDK Client.
3641
*
@@ -93,6 +98,11 @@ export function init(options: BrowserOptions = {}): void {
9398
options.defaultIntegrations = defaultIntegrations;
9499
}
95100
if (options.release === undefined) {
101+
// This allows build tooling to find-and-replace __SENTRY_RELEASE__ to inject a release value
102+
if (typeof __SENTRY_RELEASE__ === 'string') {
103+
options.release = __SENTRY_RELEASE__;
104+
}
105+
96106
// This supports the variable that sentry-webpack-plugin injects
97107
if (WINDOW.SENTRY_RELEASE && WINDOW.SENTRY_RELEASE.id) {
98108
options.release = WINDOW.SENTRY_RELEASE.id;

packages/gatsby/gatsby-browser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ exports.onClientEntry = function (_, pluginParams) {
2525
}
2626

2727
Sentry.init({
28-
// eslint-disable-next-line no-undef
29-
release: __SENTRY_RELEASE__,
3028
// eslint-disable-next-line no-undef
3129
dsn: __SENTRY_DSN__,
3230
...pluginParams,

packages/gatsby/test/gatsby-browser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ describe('onClientEntry', () => {
3737
});
3838

3939
it.each([
40-
[{}, ['dsn', 'release']],
41-
[{ key: 'value' }, ['dsn', 'release', 'key']],
40+
[{}, ['dsn']],
41+
[{ key: 'value' }, ['dsn', 'key']],
4242
])('inits Sentry by default', (pluginParams, expectedKeys) => {
4343
onClientEntry(undefined, pluginParams);
4444
expect(sentryInit).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)