Skip to content
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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 numberDiff line numberDiff 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 });
});
});