Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react): Add React version to events #12390

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
transaction_info: { source: 'route' },
type: 'transaction',
contexts: {
react: {
version: '18.2.0',
},
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
Expand Down Expand Up @@ -60,6 +63,9 @@ test('captures a navigation transcation to Sentry', async ({ page }) => {
transaction_info: { source: 'route' },
type: 'transaction',
contexts: {
react: {
version: '18.2.0',
},
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ test('Sends a pageload transaction', async ({ page }) => {
transaction_info: { source: 'url' },
type: 'transaction',
contexts: {
react: {
version: expect.any(String),
},
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { BrowserOptions } from '@sentry/browser';
import { init as browserInit } from '@sentry/browser';
import { init as browserInit, setContext } from '@sentry/browser';
import { applySdkMetadata } from '@sentry/core';

import { version } from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how nice of them to export this. I wish more packages did that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to sanity check, is this exported in all react versions (*that we support)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is


/**
* Inits the React SDK
*/
Expand All @@ -11,6 +13,6 @@ export function init(options: BrowserOptions): void {
};

applySdkMetadata(opts, 'react');

setContext('react', { version });
browserInit(opts);
}
14 changes: 14 additions & 0 deletions packages/react/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as SentryBrowser from '@sentry/browser';
import { version } from 'react';
import { init } from '../src/sdk';

describe('init', () => {
it('sets the React version (if available) in the global scope', () => {
const setContextSpy = jest.spyOn(SentryBrowser, 'setContext');

init({});

expect(setContextSpy).toHaveBeenCalledTimes(1);
expect(setContextSpy).toHaveBeenCalledWith('react', { version });
});
});
Loading