@@ -54,6 +54,44 @@ function toPercentInDecimal(value: number) {
54
54
return `${ value * 100 } %` ;
55
55
}
56
56
57
+ function SpanBarCriticalPath ( props : { criticalPathViewStart : number ; criticalPathViewEnd : number } ) {
58
+ const [ shouldLoadTooltip , setShouldLoadTooltip ] = useState ( false ) ;
59
+
60
+ const criticalPath = (
61
+ < div
62
+ data-testid = "SpanBar--criticalPath"
63
+ className = "SpanBar--criticalPath"
64
+ onMouseEnter = { ( ) => setShouldLoadTooltip ( true ) }
65
+ style = { {
66
+ background : 'black' ,
67
+ left : toPercentInDecimal ( props . criticalPathViewStart ) ,
68
+ width : toPercentInDecimal ( props . criticalPathViewEnd - props . criticalPathViewStart ) ,
69
+ } }
70
+ />
71
+ ) ;
72
+
73
+ // Load tooltip only when hovering over critical path segment
74
+ // to reduce initial load time of trace page by ~300ms for 500 spans
75
+ if ( shouldLoadTooltip ) {
76
+ return (
77
+ < Tooltip
78
+ placement = "top"
79
+ // defaultOpen is needed to show the tooltip when shouldLoadTooltip changes to true
80
+ defaultOpen
81
+ title = {
82
+ < div >
83
+ A segment on the < em > critical path</ em > of the overall trace/request/workflow.
84
+ </ div >
85
+ }
86
+ >
87
+ { criticalPath }
88
+ </ Tooltip >
89
+ ) ;
90
+ }
91
+
92
+ return criticalPath ;
93
+ }
94
+
57
95
function SpanBar ( props : TCommonProps ) {
58
96
const {
59
97
criticalPath,
@@ -145,26 +183,13 @@ function SpanBar(props: TCommonProps) {
145
183
const criticalPathViewStart = critcalPathViewBounds . start ;
146
184
const criticalPathViewEnd = critcalPathViewBounds . end ;
147
185
const key = `${ each . spanId } -${ index } ` ;
186
+
148
187
return (
149
- < Tooltip
150
- placement = "top"
151
- title = {
152
- < div >
153
- A segment on the < em > critical path</ em > of the overall trace/request/workflow.
154
- </ div >
155
- }
156
- >
157
- < div
158
- key = { key }
159
- data-testid = "SpanBar--criticalPath"
160
- className = "SpanBar--criticalPath"
161
- style = { {
162
- background : 'black' ,
163
- left : toPercentInDecimal ( criticalPathViewStart ) ,
164
- width : toPercentInDecimal ( criticalPathViewEnd - criticalPathViewStart ) ,
165
- } }
166
- />
167
- </ Tooltip >
188
+ < SpanBarCriticalPath
189
+ criticalPathViewStart = { criticalPathViewStart }
190
+ criticalPathViewEnd = { criticalPathViewEnd }
191
+ key = { key }
192
+ />
168
193
) ;
169
194
} ) }
170
195
</ div >
0 commit comments