Skip to content

Commit ba80e9d

Browse files
committed
set browser SDK data globally
1 parent 25f7fc6 commit ba80e9d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/browser/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
export * from './exports';
22

33
import { Integrations as CoreIntegrations } from '@sentry/core';
4-
import { getGlobalObject } from '@sentry/utils';
4+
import { getGlobalObject, setSDKInfo } from '@sentry/utils';
55

66
import * as BrowserIntegrations from './integrations';
77
import * as Transports from './transports';
8+
import { SDK_VERSION } from './version';
9+
10+
setSDKInfo('sentry.javascript.browser', 'npm:@sentry/browser', SDK_VERSION, false);
811

912
let windowIntegrations = {};
1013

packages/browser/test/unit/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
init,
1515
Integrations,
1616
Scope,
17+
SDK_VERSION,
1718
wrap,
1819
} from '../../src';
1920
import { SimpleTransport } from './mocks/simpletransport';
@@ -171,6 +172,16 @@ describe('SentryBrowser', () => {
171172
});
172173

173174
describe('SentryBrowser initialization', () => {
175+
it('should set SDK info globally', () => {
176+
// the SDK data is set when we import from (and therefore run) `../src/index.ts`, so no action is necessary here
177+
// before we run the `expect`s
178+
179+
expect(global.__SENTRY__.sdkInfo).to.exist;
180+
expect(global.__SENTRY__.sdkInfo.name).to.equal('sentry.javascript.browser');
181+
expect(global.__SENTRY__.sdkInfo.version).to.equal(SDK_VERSION);
182+
expect(global.__SENTRY__.sdkInfo.packages).to.deep.equal([{ name: 'npm:@sentry/browser', version: SDK_VERSION }]);
183+
});
184+
174185
it('should use window.SENTRY_RELEASE to set release on initialization if available', () => {
175186
global.SENTRY_RELEASE = { id: 'foobar' };
176187
init({ dsn });

0 commit comments

Comments
 (0)