Skip to content

Commit 2daa748

Browse files
committed
feat(react): Add React version to events
1 parent 0a6c1e5 commit 2daa748

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/react/src/sdk.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { BrowserOptions } from '@sentry/browser';
2-
import { init as browserInit } from '@sentry/browser';
2+
import { init as browserInit, setContext } from '@sentry/browser';
33
import { applySdkMetadata } from '@sentry/core';
44

5+
import { version } from 'react';
6+
57
/**
68
* Inits the React SDK
79
*/
@@ -11,6 +13,6 @@ export function init(options: BrowserOptions): void {
1113
};
1214

1315
applySdkMetadata(opts, 'react');
14-
16+
setContext('react', { version });
1517
browserInit(opts);
1618
}

packages/react/test/sdk.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as SentryBrowser from '@sentry/browser';
2+
import { version } from 'react';
3+
import { init } from '../src/sdk';
4+
5+
describe('init', () => {
6+
it('sets the React version (if available) in the global scope', () => {
7+
const setContextSpy = jest.spyOn(SentryBrowser, 'setContext');
8+
9+
init({});
10+
11+
// In our case, the Angular version is 10 because that's the version we use for compilation
12+
// (and hence the dependency version of Angular core we installed (see package.json))
13+
expect(setContextSpy).toHaveBeenCalledTimes(1);
14+
expect(setContextSpy).toHaveBeenCalledWith('react', { version });
15+
});
16+
});

0 commit comments

Comments
 (0)