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
5 changes: 5 additions & 0 deletions packages/react/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const REACT_RENDER_OP = 'ui.react.render';

export const REACT_UPDATE_OP = 'ui.react.update';

export const REACT_MOUNT_OP = 'ui.react.mount';
16 changes: 9 additions & 7 deletions packages/react/src/profiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { timestampWithMs } from '@sentry/utils';
import hoistNonReactStatics from 'hoist-non-react-statics';
import * as React from 'react';

import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';

export const UNKNOWN_COMPONENT = 'unknown';

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

return (globalTracingIntegration as any).constructor.pushActivity(name, {
description: `<${name}>`,
op: `react.${op}`,
op,
});
}

Expand Down Expand Up @@ -115,13 +117,13 @@ class Profiler extends React.Component<ProfilerProps> {
// eslint-disable-next-line deprecation/deprecation
if (getTracingIntegration()) {
// eslint-disable-next-line deprecation/deprecation
this._mountActivity = pushActivity(name, 'mount');
this._mountActivity = pushActivity(name, REACT_MOUNT_OP);
} else {
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
this._mountSpan = activeTransaction.startChild({
description: `<${name}>`,
op: 'react.mount',
op: REACT_MOUNT_OP,
});
}
}
Expand Down Expand Up @@ -158,7 +160,7 @@ class Profiler extends React.Component<ProfilerProps> {
},
description: `<${this.props.name}>`,
endTimestamp: now,
op: `react.update`,
op: REACT_UPDATE_OP,
startTimestamp: now,
});
}
Expand All @@ -176,7 +178,7 @@ class Profiler extends React.Component<ProfilerProps> {
this._mountSpan.startChild({
description: `<${name}>`,
endTimestamp: timestampWithMs(),
op: `react.render`,
op: REACT_RENDER_OP,
startTimestamp: this._mountSpan.endTimestamp,
});
}
Expand Down Expand Up @@ -240,7 +242,7 @@ function useProfiler(
if (activeTransaction) {
return activeTransaction.startChild({
description: `<${name}>`,
op: 'react.mount',
op: REACT_MOUNT_OP,
});
}

Expand All @@ -257,7 +259,7 @@ function useProfiler(
mountSpan.startChild({
description: `<${name}>`,
endTimestamp: timestampWithMs(),
op: `react.render`,
op: REACT_RENDER_OP,
startTimestamp: mountSpan.endTimestamp,
});
}
Expand Down
13 changes: 7 additions & 6 deletions packages/react/test/profiler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import * as React from 'react';

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

const mockStartChild = jest.fn((spanArgs: SpanContext) => ({ ...spanArgs }));
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('withProfiler', () => {
expect(mockStartChild).toHaveBeenCalledTimes(1);
expect(mockStartChild).toHaveBeenLastCalledWith({
description: `<${UNKNOWN_COMPONENT}>`,
op: 'react.mount',
op: REACT_MOUNT_OP,
});
});
});
Expand All @@ -93,7 +94,7 @@ describe('withProfiler', () => {
expect(mockStartChild).toHaveBeenLastCalledWith({
description: `<${UNKNOWN_COMPONENT}>`,
endTimestamp: expect.any(Number),
op: 'react.render',
op: REACT_RENDER_OP,
startTimestamp: undefined,
});
});
Expand Down Expand Up @@ -122,7 +123,7 @@ describe('withProfiler', () => {
data: { changedProps: ['num'] },
description: `<${UNKNOWN_COMPONENT}>`,
endTimestamp: expect.any(Number),
op: 'react.update',
op: REACT_UPDATE_OP,
startTimestamp: expect.any(Number),
});

Expand All @@ -133,7 +134,7 @@ describe('withProfiler', () => {
data: { changedProps: ['num'] },
description: `<${UNKNOWN_COMPONENT}>`,
endTimestamp: expect.any(Number),
op: 'react.update',
op: REACT_UPDATE_OP,
startTimestamp: expect.any(Number),
});

Expand Down Expand Up @@ -169,7 +170,7 @@ describe('useProfiler()', () => {
expect(mockStartChild).toHaveBeenCalledTimes(1);
expect(mockStartChild).toHaveBeenLastCalledWith({
description: '<Example>',
op: 'react.mount',
op: REACT_MOUNT_OP,
});
});
});
Expand All @@ -191,7 +192,7 @@ describe('useProfiler()', () => {
expect(mockStartChild).toHaveBeenLastCalledWith(
expect.objectContaining({
description: '<Example>',
op: 'react.render',
op: REACT_RENDER_OP,
}),
);
});
Expand Down