Skip to content

Commit 643823f

Browse files
committed
set react SDK data globally
1 parent 8d90b40 commit 643823f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/react/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { addGlobalEventProcessor, SDK_VERSION } from '@sentry/browser';
2+
import { setSDKInfo } from '@sentry/utils';
3+
4+
setSDKInfo('sentry.javascript.react', 'npm:@sentry/react', SDK_VERSION);
25

36
/**
47
* A global side effect that makes sure Sentry events that user

packages/react/test/init.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getGlobalObject } from '@sentry/utils';
2+
3+
import * as Sentry from '../src/index';
4+
5+
const global = getGlobalObject<Window>();
6+
7+
describe('event SDK info', () => {
8+
it('adds SDK metadata globally', () => {
9+
// the SDK data is set when we import from (and therefore run) `../src/index.ts` - it sets the react part itself,
10+
// and the browser part gets set when it imports from @sentry/browser - so no action is necessary here before we run
11+
// the `expect`s
12+
13+
expect(global.__SENTRY__?.sdkInfo).toBeDefined();
14+
expect(global.__SENTRY__?.sdkInfo?.name).toEqual('sentry.javascript.react');
15+
expect(global.__SENTRY__?.sdkInfo?.version).toEqual(Sentry.SDK_VERSION);
16+
expect(global.__SENTRY__?.sdkInfo?.packages).toEqual(
17+
expect.arrayContaining([
18+
{ name: 'npm:@sentry/react', version: Sentry.SDK_VERSION },
19+
{ name: 'npm:@sentry/browser', version: Sentry.SDK_VERSION },
20+
]),
21+
);
22+
});
23+
});

0 commit comments

Comments
 (0)