Skip to content

Commit e9ede2d

Browse files
AbhiPrasadonurtemizkan
authored andcommitted
fix(react): Use ui category for operations (#4218)
As per the new spec in https://develop.sentry.dev/sdk/performance/span-operations/#js-frameworks, we now want to prefix our react spans operations with `ui`.
1 parent 8d8418c commit e9ede2d

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

packages/react/src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const REACT_RENDER_OP = 'ui.react.render';
2+
3+
export const REACT_UPDATE_OP = 'ui.react.update';
4+
5+
export const REACT_MOUNT_OP = 'ui.react.mount';

packages/react/src/profiler.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { timestampWithMs } from '@sentry/utils';
66
import hoistNonReactStatics from 'hoist-non-react-statics';
77
import * as React from 'react';
88

9+
import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';
10+
911
export const UNKNOWN_COMPONENT = 'unknown';
1012

1113
const TRACING_GETTER = ({
@@ -36,7 +38,7 @@ function pushActivity(name: string, op: string): number | null {
3638

3739
return (globalTracingIntegration as any).constructor.pushActivity(name, {
3840
description: `<${name}>`,
39-
op: `react.${op}`,
41+
op,
4042
});
4143
}
4244

@@ -115,13 +117,13 @@ class Profiler extends React.Component<ProfilerProps> {
115117
// eslint-disable-next-line deprecation/deprecation
116118
if (getTracingIntegration()) {
117119
// eslint-disable-next-line deprecation/deprecation
118-
this._mountActivity = pushActivity(name, 'mount');
120+
this._mountActivity = pushActivity(name, REACT_MOUNT_OP);
119121
} else {
120122
const activeTransaction = getActiveTransaction();
121123
if (activeTransaction) {
122124
this._mountSpan = activeTransaction.startChild({
123125
description: `<${name}>`,
124-
op: 'react.mount',
126+
op: REACT_MOUNT_OP,
125127
});
126128
}
127129
}
@@ -158,7 +160,7 @@ class Profiler extends React.Component<ProfilerProps> {
158160
},
159161
description: `<${this.props.name}>`,
160162
endTimestamp: now,
161-
op: `react.update`,
163+
op: REACT_UPDATE_OP,
162164
startTimestamp: now,
163165
});
164166
}
@@ -176,7 +178,7 @@ class Profiler extends React.Component<ProfilerProps> {
176178
this._mountSpan.startChild({
177179
description: `<${name}>`,
178180
endTimestamp: timestampWithMs(),
179-
op: `react.render`,
181+
op: REACT_RENDER_OP,
180182
startTimestamp: this._mountSpan.endTimestamp,
181183
});
182184
}
@@ -240,7 +242,7 @@ function useProfiler(
240242
if (activeTransaction) {
241243
return activeTransaction.startChild({
242244
description: `<${name}>`,
243-
op: 'react.mount',
245+
op: REACT_MOUNT_OP,
244246
});
245247
}
246248

@@ -257,7 +259,7 @@ function useProfiler(
257259
mountSpan.startChild({
258260
description: `<${name}>`,
259261
endTimestamp: timestampWithMs(),
260-
op: `react.render`,
262+
op: REACT_RENDER_OP,
261263
startTimestamp: mountSpan.endTimestamp,
262264
});
263265
}

packages/react/test/profiler.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render } from '@testing-library/react';
33
import { renderHook } from '@testing-library/react-hooks';
44
import * as React from 'react';
55

6+
import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from '../src/constants';
67
import { UNKNOWN_COMPONENT, useProfiler, withProfiler } from '../src/profiler';
78

89
const mockStartChild = jest.fn((spanArgs: SpanContext) => ({ ...spanArgs }));
@@ -76,7 +77,7 @@ describe('withProfiler', () => {
7677
expect(mockStartChild).toHaveBeenCalledTimes(1);
7778
expect(mockStartChild).toHaveBeenLastCalledWith({
7879
description: `<${UNKNOWN_COMPONENT}>`,
79-
op: 'react.mount',
80+
op: REACT_MOUNT_OP,
8081
});
8182
});
8283
});
@@ -93,7 +94,7 @@ describe('withProfiler', () => {
9394
expect(mockStartChild).toHaveBeenLastCalledWith({
9495
description: `<${UNKNOWN_COMPONENT}>`,
9596
endTimestamp: expect.any(Number),
96-
op: 'react.render',
97+
op: REACT_RENDER_OP,
9798
startTimestamp: undefined,
9899
});
99100
});
@@ -122,7 +123,7 @@ describe('withProfiler', () => {
122123
data: { changedProps: ['num'] },
123124
description: `<${UNKNOWN_COMPONENT}>`,
124125
endTimestamp: expect.any(Number),
125-
op: 'react.update',
126+
op: REACT_UPDATE_OP,
126127
startTimestamp: expect.any(Number),
127128
});
128129

@@ -133,7 +134,7 @@ describe('withProfiler', () => {
133134
data: { changedProps: ['num'] },
134135
description: `<${UNKNOWN_COMPONENT}>`,
135136
endTimestamp: expect.any(Number),
136-
op: 'react.update',
137+
op: REACT_UPDATE_OP,
137138
startTimestamp: expect.any(Number),
138139
});
139140

@@ -169,7 +170,7 @@ describe('useProfiler()', () => {
169170
expect(mockStartChild).toHaveBeenCalledTimes(1);
170171
expect(mockStartChild).toHaveBeenLastCalledWith({
171172
description: '<Example>',
172-
op: 'react.mount',
173+
op: REACT_MOUNT_OP,
173174
});
174175
});
175176
});
@@ -191,7 +192,7 @@ describe('useProfiler()', () => {
191192
expect(mockStartChild).toHaveBeenLastCalledWith(
192193
expect.objectContaining({
193194
description: '<Example>',
194-
op: 'react.render',
195+
op: REACT_RENDER_OP,
195196
}),
196197
);
197198
});

0 commit comments

Comments
 (0)