@@ -39,24 +39,37 @@ function afterNextFrame(callback: Function): void {
39
39
timeout = window . setTimeout ( done , 100 ) ;
40
40
}
41
41
42
+ let globalTracingIntegration : Integration | null = null ;
43
+ const getTracingIntegration = ( ) => {
44
+ if ( globalTracingIntegration ) {
45
+ return globalTracingIntegration ;
46
+ }
47
+
48
+ globalTracingIntegration = getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ;
49
+ return globalTracingIntegration ;
50
+ } ;
51
+
52
+ /** JSDOC */
53
+ function warnAboutTracing ( name : string ) : void {
54
+ if ( globalTracingIntegration === null ) {
55
+ logger . warn (
56
+ `Unable to profile component ${ name } due to invalid Tracing Integration. Please make sure to setup the Tracing integration.` ,
57
+ ) ;
58
+ }
59
+ }
60
+
42
61
/**
43
62
* getInitActivity pushes activity based on React component mount
44
63
* @param name displayName of component that started activity
45
64
*/
46
65
const getInitActivity = ( name : string ) : number | null => {
47
- const tracingIntegration = getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ;
48
-
49
- if ( tracingIntegration !== null ) {
66
+ if ( globalTracingIntegration !== null ) {
50
67
// tslint:disable-next-line:no-unsafe-any
51
- return ( tracingIntegration as any ) . constructor . pushActivity ( name , {
68
+ return ( globalTracingIntegration as any ) . constructor . pushActivity ( name , {
52
69
description : `<${ name } >` ,
53
70
op : 'react' ,
54
71
} ) ;
55
72
}
56
-
57
- logger . warn (
58
- `Unable to profile component ${ name } due to invalid Tracing Integration. Please make sure to setup the Tracing integration.` ,
59
- ) ;
60
73
return null ;
61
74
} ;
62
75
@@ -65,11 +78,17 @@ export type ProfilerProps = {
65
78
} ;
66
79
67
80
class Profiler extends React . Component < ProfilerProps > {
68
- public activity : number | null ;
81
+ public activity : number | null = null ;
82
+ public tracingIntegration : Integration | null = getTracingIntegration ( ) ;
83
+
69
84
public constructor ( props : ProfilerProps ) {
70
85
super ( props ) ;
71
86
72
- this . activity = getInitActivity ( this . props . name ) ;
87
+ if ( this . tracingIntegration ) {
88
+ this . activity = getInitActivity ( this . props . name ) ;
89
+ } else {
90
+ warnAboutTracing ( this . props . name ) ;
91
+ }
73
92
}
74
93
75
94
// If a component mounted, we can finish the mount activity.
@@ -84,16 +103,13 @@ class Profiler extends React.Component<ProfilerProps> {
84
103
}
85
104
86
105
public finishProfile = ( ) => {
87
- if ( ! this . activity ) {
106
+ if ( ! this . activity || ! this . tracingIntegration ) {
88
107
return ;
89
108
}
90
109
91
- const tracingIntegration = getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ;
92
- if ( tracingIntegration !== null ) {
93
- // tslint:disable-next-line:no-unsafe-any
94
- ( tracingIntegration as any ) . constructor . popActivity ( this . activity ) ;
95
- this . activity = null ;
96
- }
110
+ // tslint:disable-next-line:no-unsafe-any
111
+ ( this . tracingIntegration as any ) . constructor . popActivity ( this . activity ) ;
112
+ this . activity = null ;
97
113
} ;
98
114
99
115
public render ( ) : React . ReactNode {
0 commit comments