Skip to content

Commit 811eb29

Browse files
committed
feat(react): Send component name on spans
1 parent d152364 commit 811eb29

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/react/src/profiler.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Profiler extends React.Component<ProfilerProps> {
6363
description: `<${name}>`,
6464
op: REACT_MOUNT_OP,
6565
origin: 'auto.ui.react.profiler',
66+
data: { 'ui.component_name': name },
6667
});
6768
}
6869
}
@@ -87,6 +88,7 @@ class Profiler extends React.Component<ProfilerProps> {
8788
this._updateSpan = this._mountSpan.startChild({
8889
data: {
8990
changedProps,
91+
'ui.component_name': this.props.name,
9092
},
9193
description: `<${this.props.name}>`,
9294
op: REACT_UPDATE_OP,
@@ -120,6 +122,7 @@ class Profiler extends React.Component<ProfilerProps> {
120122
op: REACT_RENDER_OP,
121123
origin: 'auto.ui.react.profiler',
122124
startTimestamp: this._mountSpan.endTimestamp,
125+
data: { 'ui.component_name': name },
123126
});
124127
}
125128
}
@@ -184,6 +187,7 @@ function useProfiler(
184187
description: `<${name}>`,
185188
op: REACT_MOUNT_OP,
186189
origin: 'auto.ui.react.profiler',
190+
data: { 'ui.component_name': name },
187191
});
188192
}
189193

@@ -203,6 +207,7 @@ function useProfiler(
203207
op: REACT_RENDER_OP,
204208
origin: 'auto.ui.react.profiler',
205209
startTimestamp: mountSpan.endTimestamp,
210+
data: { 'ui.component_name': name },
206211
});
207212
}
208213
};

packages/react/test/profiler.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe('withProfiler', () => {
8080
description: `<${UNKNOWN_COMPONENT}>`,
8181
op: REACT_MOUNT_OP,
8282
origin: 'auto.ui.react.profiler',
83+
data: { 'ui.component_name': 'unknown' },
8384
});
8485
});
8586
});
@@ -99,6 +100,7 @@ describe('withProfiler', () => {
99100
op: REACT_RENDER_OP,
100101
origin: 'auto.ui.react.profiler',
101102
startTimestamp: undefined,
103+
data: { 'ui.component_name': 'unknown' },
102104
});
103105
});
104106

@@ -114,7 +116,6 @@ describe('withProfiler', () => {
114116
expect(mockStartChild).toHaveBeenCalledTimes(1);
115117
});
116118
});
117-
118119
describe('update span', () => {
119120
it('is created when component is updated', () => {
120121
const ProfiledComponent = withProfiler((props: { num: number }) => <div>{props.num}</div>);
@@ -126,7 +127,7 @@ describe('withProfiler', () => {
126127
rerender(<ProfiledComponent num={1} />);
127128
expect(mockStartChild).toHaveBeenCalledTimes(2);
128129
expect(mockStartChild).toHaveBeenLastCalledWith({
129-
data: { changedProps: ['num'] },
130+
data: { changedProps: ['num'], 'ui.component_name': 'unknown' },
130131
description: `<${UNKNOWN_COMPONENT}>`,
131132
op: REACT_UPDATE_OP,
132133
origin: 'auto.ui.react.profiler',
@@ -137,7 +138,7 @@ describe('withProfiler', () => {
137138
rerender(<ProfiledComponent num={2} />);
138139
expect(mockStartChild).toHaveBeenCalledTimes(3);
139140
expect(mockStartChild).toHaveBeenLastCalledWith({
140-
data: { changedProps: ['num'] },
141+
data: { changedProps: ['num'], 'ui.component_name': 'unknown' },
141142
description: `<${UNKNOWN_COMPONENT}>`,
142143
op: REACT_UPDATE_OP,
143144
origin: 'auto.ui.react.profiler',
@@ -180,6 +181,7 @@ describe('useProfiler()', () => {
180181
description: '<Example>',
181182
op: REACT_MOUNT_OP,
182183
origin: 'auto.ui.react.profiler',
184+
data: { 'ui.component_name': 'Example' },
183185
});
184186
});
185187
});
@@ -203,6 +205,7 @@ describe('useProfiler()', () => {
203205
description: '<Example>',
204206
op: REACT_RENDER_OP,
205207
origin: 'auto.ui.react.profiler',
208+
data: { 'ui.component_name': 'Example' },
206209
}),
207210
);
208211
});

0 commit comments

Comments
 (0)