Skip to content

Commit 4eddf1a

Browse files
committed
ref: Add visibleActivity:
1 parent dc0d9ba commit 4eddf1a

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

packages/react/src/profiler.tsx

+24-18
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ function warnAboutTracing(name: string): void {
6262
* pushActivity creates an new react activity
6363
* @param name displayName of component that started activity
6464
*/
65-
const pushActivity = (name: string): number | null => {
65+
const pushActivity = (name: string, op: string, options?: Object): number | null => {
6666
if (globalTracingIntegration === null) {
6767
return null;
6868
}
6969

7070
// tslint:disable-next-line:no-unsafe-any
71-
return (globalTracingIntegration as any).constructor.pushActivity(name, {
72-
description: `<${name}>`,
73-
op: 'react',
74-
});
71+
return (globalTracingIntegration as any).constructor.pushActivity(
72+
name,
73+
{
74+
description: `<${name}>`,
75+
op: `react.${op}`,
76+
},
77+
options,
78+
);
7579
};
7680

7781
/**
@@ -99,10 +103,10 @@ export type ProfilerProps = {
99103
* spans based on component lifecycles.
100104
*/
101105
class Profiler extends React.Component<ProfilerProps> {
102-
public activity: number | null = null;
103-
// The activity representing when a component was mounted onto a page.
104106
public mountInfo: {
107+
// The activity representing when a component was mounted onto a page.
105108
activity: number | null;
109+
// The span from the mountInfo activity
106110
span: Span | null;
107111
} = {
108112
activity: null,
@@ -120,29 +124,31 @@ class Profiler extends React.Component<ProfilerProps> {
120124
}
121125

122126
if (getTracingIntegration()) {
123-
this.activity = pushActivity(name);
127+
this.mountInfo.activity = pushActivity(name, 'mount');
124128
} else {
125129
warnAboutTracing(name);
126130
}
127131
}
128132

129133
// If a component mounted, we can finish the mount activity.
130134
public componentDidMount(): void {
131-
afterNextFrame(this.finishProfile);
132-
}
135+
afterNextFrame(() => {
136+
popActivity(this.mountInfo.activity);
137+
this.mountInfo.activity = null;
133138

134-
// Sometimes a component will unmount first, so we make
135-
// sure to also finish the mount activity here.
136-
public componentWillUnmount(): void {
137-
afterNextFrame(this.finishProfile);
139+
this.visibleActivity = pushActivity(this.props.name, 'visible');
140+
});
138141
}
139142

140-
public finishProfile = () => {
143+
// If a component doesn't mount, the visible activity will be end when the
144+
public componentWillUnmount(): void {
141145
afterNextFrame(() => {
142-
popActivity(this.activity);
143-
this.activity = null;
146+
popActivity(this.visibleActivity);
147+
this.visibleActivity = null;
144148
});
145-
};
149+
}
150+
151+
public finishProfile = () => {};
146152

147153
public render(): React.ReactNode {
148154
return this.props.children;

0 commit comments

Comments
 (0)