@@ -62,16 +62,20 @@ function warnAboutTracing(name: string): void {
62
62
* pushActivity creates an new react activity
63
63
* @param name displayName of component that started activity
64
64
*/
65
- const pushActivity = ( name : string ) : number | null => {
65
+ const pushActivity = ( name : string , op : string , options ?: Object ) : number | null => {
66
66
if ( globalTracingIntegration === null ) {
67
67
return null ;
68
68
}
69
69
70
70
// 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
+ ) ;
75
79
} ;
76
80
77
81
/**
@@ -99,10 +103,10 @@ export type ProfilerProps = {
99
103
* spans based on component lifecycles.
100
104
*/
101
105
class Profiler extends React . Component < ProfilerProps > {
102
- public activity : number | null = null ;
103
- // The activity representing when a component was mounted onto a page.
104
106
public mountInfo : {
107
+ // The activity representing when a component was mounted onto a page.
105
108
activity : number | null ;
109
+ // The span from the mountInfo activity
106
110
span : Span | null ;
107
111
} = {
108
112
activity : null ,
@@ -120,29 +124,31 @@ class Profiler extends React.Component<ProfilerProps> {
120
124
}
121
125
122
126
if ( getTracingIntegration ( ) ) {
123
- this . activity = pushActivity ( name ) ;
127
+ this . mountInfo . activity = pushActivity ( name , 'mount' ) ;
124
128
} else {
125
129
warnAboutTracing ( name ) ;
126
130
}
127
131
}
128
132
129
133
// If a component mounted, we can finish the mount activity.
130
134
public componentDidMount ( ) : void {
131
- afterNextFrame ( this . finishProfile ) ;
132
- }
135
+ afterNextFrame ( ( ) => {
136
+ popActivity ( this . mountInfo . activity ) ;
137
+ this . mountInfo . activity = null ;
133
138
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
+ } ) ;
138
141
}
139
142
140
- public finishProfile = ( ) => {
143
+ // If a component doesn't mount, the visible activity will be end when the
144
+ public componentWillUnmount ( ) : void {
141
145
afterNextFrame ( ( ) => {
142
- popActivity ( this . activity ) ;
143
- this . activity = null ;
146
+ popActivity ( this . visibleActivity ) ;
147
+ this . visibleActivity = null ;
144
148
} ) ;
145
- } ;
149
+ }
150
+
151
+ public finishProfile = ( ) => { } ;
146
152
147
153
public render ( ) : React . ReactNode {
148
154
return this . props . children ;
0 commit comments