1
1
import { getCurrentHub } from '@sentry/browser' ;
2
- import { Integration , IntegrationClass , Span , SpanContext } from '@sentry/types' ;
2
+ import { Integration , IntegrationClass , Span } from '@sentry/types' ;
3
3
import { logger , timestampWithMs } from '@sentry/utils' ;
4
4
import * as hoistNonReactStatic from 'hoist-non-react-statics' ;
5
5
import * as React from 'react' ;
@@ -68,7 +68,6 @@ function warnAboutTracing(name: string): void {
68
68
function pushActivity (
69
69
name : string ,
70
70
op : string ,
71
- context ?: SpanContext ,
72
71
options ?: {
73
72
autoPopAfter ?: number ;
74
73
parentSpanId ?: string ;
@@ -84,7 +83,6 @@ function pushActivity(
84
83
{
85
84
description : `<${ name } >` ,
86
85
op : `react.${ op } ` ,
87
- ...context ,
88
86
} ,
89
87
options ,
90
88
) ;
@@ -96,13 +94,13 @@ function pushActivity(
96
94
* @param activity id of activity that is being popped
97
95
* @param finish if a span should be finished after the activity is removed
98
96
*/
99
- function popActivity ( activity : number | null , finish : boolean = true ) : void {
97
+ function popActivity ( activity : number | null ) : void {
100
98
if ( activity === null || globalTracingIntegration === null ) {
101
99
return ;
102
100
}
103
101
104
102
// tslint:disable-next-line:no-unsafe-any
105
- ( globalTracingIntegration as any ) . constructor . popActivity ( activity , undefined , finish ) ;
103
+ ( globalTracingIntegration as any ) . constructor . popActivity ( activity , undefined ) ;
106
104
}
107
105
108
106
function getActivitySpan ( activity : number | null ) : Span | undefined {
@@ -130,14 +128,15 @@ export type ProfilerProps = {
130
128
class Profiler extends React . Component < ProfilerProps > {
131
129
// The activity representing how long it takes to mount a component.
132
130
public mountActivity : number | null = null ;
133
- // The spanId of the mount activity
134
- public mountSpanId : string | null = null ;
131
+ // The span of the mount activity
132
+ public span : Span | undefined = undefined ;
135
133
// The activity representing how long a component was on the page.
136
134
public renderActivity : number | null = null ;
135
+ public renderSpan : Span | undefined = undefined ;
137
136
138
137
public static defaultProps : Partial < ProfilerProps > = {
139
138
disabled : false ,
140
- generateUpdateSpans : false ,
139
+ generateUpdateSpans : true ,
141
140
} ;
142
141
143
142
public constructor ( props : ProfilerProps ) {
@@ -157,42 +156,42 @@ class Profiler extends React.Component<ProfilerProps> {
157
156
158
157
// If a component mounted, we can finish the mount activity.
159
158
public componentDidMount ( ) : void {
160
- afterNextFrame ( ( ) => {
161
- const span = getActivitySpan ( this . mountActivity ) ;
162
- if ( span ) {
163
- this . mountSpanId = span . spanId ;
164
- }
165
- popActivity ( this . mountActivity ) ;
166
- this . mountActivity = null ;
167
-
168
- // If we were able to obtain the spanId of the mount activity, we should set the
169
- // next activity as a child to the component mount activity.
170
- const options = span ? { parentSpanId : span . spanId } : { } ;
171
- this . renderActivity = pushActivity ( this . props . name , 'render' , { } , options ) ;
172
- } ) ;
159
+ // afterNextFrame(() => {
160
+ this . span = getActivitySpan ( this . mountActivity ) ;
161
+ popActivity ( this . mountActivity ) ;
162
+ this . mountActivity = null ;
163
+
164
+ // If we were able to obtain the spanId of the mount activity, we should set the
165
+ // next activity as a child to the component mount activity.
166
+ if ( this . span ) {
167
+ this . renderSpan = this . span . startChild ( {
168
+ description : `<${ this . props . name } >` ,
169
+ op : `react.render` ,
170
+ } ) ;
171
+ }
172
+ // });
173
173
}
174
174
175
175
public componentDidUpdate ( prevProps : ProfilerProps ) : void {
176
- if ( prevProps . generateUpdateSpans && this . mountSpanId ) {
176
+ if ( prevProps . generateUpdateSpans && this . span && prevProps !== this . props ) {
177
177
const now = timestampWithMs ( ) ;
178
- const updateActivity = pushActivity (
179
- prevProps . name ,
180
- 'update' ,
181
- {
182
- endTimestamp : now ,
183
- startTimestamp : now ,
184
- } ,
185
- { parentSpanId : this . mountSpanId } ,
186
- ) ;
187
- popActivity ( updateActivity , false ) ;
178
+ this . span . startChild ( {
179
+ description : `<${ prevProps . name } >` ,
180
+ endTimestamp : now ,
181
+ op : `react.update` ,
182
+ startTimestamp : now ,
183
+ } ) ;
188
184
}
189
185
}
190
186
191
187
// If a component doesn't mount, the render activity will be end when the
192
188
public componentWillUnmount ( ) : void {
193
189
afterNextFrame ( ( ) => {
194
- popActivity ( this . renderActivity , false ) ;
195
- this . renderActivity = null ;
190
+ if ( this . renderSpan ) {
191
+ this . renderSpan . finish ( ) ;
192
+ }
193
+ // popActivity(this.renderActivity);
194
+ // this.renderActivity = null;
196
195
} ) ;
197
196
}
198
197
0 commit comments