@@ -2,6 +2,7 @@ import styled from '@emotion/styled';
2
2
3
3
import { Tooltip } from 'sentry/components/core/tooltip' ;
4
4
import { space } from 'sentry/styles/space' ;
5
+ import { defined } from 'sentry/utils' ;
5
6
import getDuration from 'sentry/utils/duration/getDuration' ;
6
7
import { VITAL_DETAILS } from 'sentry/utils/performance/vitals/constants' ;
7
8
import type { Vital } from 'sentry/utils/performance/vitals/types' ;
@@ -18,7 +19,13 @@ import {
18
19
STATUS_TEXT ,
19
20
} from 'sentry/views/insights/browser/webVitals/utils/scoreToStatus' ;
20
21
import type { TraceRootEventQueryResults } from 'sentry/views/performance/newTraceDetails/traceApi/useTraceRootEvent' ;
22
+ import { isTraceItemDetailsResponse } from 'sentry/views/performance/newTraceDetails/traceApi/utils' ;
23
+ import { isEAPTraceNode } from 'sentry/views/performance/newTraceDetails/traceGuards' ;
21
24
import type { TraceTree } from 'sentry/views/performance/newTraceDetails/traceModels/traceTree' ;
25
+ import {
26
+ TRACE_VIEW_MOBILE_VITALS ,
27
+ TRACE_VIEW_WEB_VITALS ,
28
+ } from 'sentry/views/performance/newTraceDetails/traceModels/traceTree.measurements' ;
22
29
import { useTraceContextSections } from 'sentry/views/performance/newTraceDetails/useTraceContextSections' ;
23
30
24
31
type Props = {
@@ -29,18 +36,31 @@ type Props = {
29
36
30
37
export function TraceContextVitals ( { rootEventResults, tree, logs} : Props ) {
31
38
const { hasVitals} = useTraceContextSections ( { tree, rootEventResults, logs} ) ;
39
+ const traceNode = tree . root . children [ 0 ] ;
32
40
33
- if ( ! hasVitals ) {
41
+ // TODO Abdullah Khan: Ignoring loading/error states for now
42
+ if ( ! hasVitals || ! rootEventResults . data || ! traceNode ) {
34
43
return null ;
35
44
}
36
45
37
- const allVitals = Array . from ( tree . vitals . values ( ) ) . flat ( ) ;
38
- return allVitals . map ( vital => {
46
+ const vitalsToDisplay = tree . vital_types . has ( 'web' )
47
+ ? TRACE_VIEW_WEB_VITALS
48
+ : TRACE_VIEW_MOBILE_VITALS ;
49
+
50
+ const isEAPTrace = isEAPTraceNode ( traceNode ) ;
51
+ const collectedVitals =
52
+ isEAPTrace && tree . vital_types . has ( 'mobile' )
53
+ ? getMobileVitalsFromRootEventResults ( rootEventResults . data )
54
+ : Array . from ( tree . vitals . values ( ) ) . flat ( ) ;
55
+
56
+ return vitalsToDisplay . map ( vitalKey => {
39
57
const vitalDetails =
40
- VITAL_DETAILS [ `measurements.${ vital . key } ` as keyof typeof VITAL_DETAILS ] ;
58
+ VITAL_DETAILS [ `measurements.${ vitalKey } ` as keyof typeof VITAL_DETAILS ] ;
59
+ const vital = collectedVitals . find ( v => v . key === vitalKey ) ;
60
+
41
61
return (
42
62
< VitalPill
43
- key = { vital ?. key }
63
+ key = { vitalKey }
44
64
vital = { vitalDetails }
45
65
score = { vital ?. score }
46
66
meterValue = { vital ?. measurement . value }
@@ -49,6 +69,31 @@ export function TraceContextVitals({rootEventResults, tree, logs}: Props) {
49
69
} ) ;
50
70
}
51
71
72
+ function getMobileVitalsFromRootEventResults (
73
+ data : TraceRootEventQueryResults [ 'data' ]
74
+ ) : TraceTree . CollectedVital [ ] {
75
+ if ( ! data || ! isTraceItemDetailsResponse ( data ) ) {
76
+ return [ ] ;
77
+ }
78
+
79
+ return data . attributes
80
+ . map ( attribute => {
81
+ const vitalKey = attribute . name . replace ( 'measurements.' , '' ) ;
82
+ if (
83
+ TRACE_VIEW_MOBILE_VITALS . includes ( vitalKey ) &&
84
+ typeof attribute . value === 'number'
85
+ ) {
86
+ return {
87
+ key : vitalKey ,
88
+ measurement : { value : attribute . value } ,
89
+ score : undefined ,
90
+ } ;
91
+ }
92
+ return undefined ;
93
+ } )
94
+ . filter ( defined ) ;
95
+ }
96
+
52
97
function defaultVitalValueFormatter ( vital : Vital , value : number ) {
53
98
if ( vital ?. type === 'duration' ) {
54
99
return getDuration ( value / 1000 , 2 , true ) ;
@@ -106,7 +151,7 @@ const VitalPillContainer = styled('div')`
106
151
flex-grow: 1;
107
152
max-width: 20%;
108
153
height: 30px;
109
- margin-bottom : ${ space ( 1 ) } ;
154
+ margin: ${ space ( 1 ) } 0 ;
110
155
` ;
111
156
112
157
const VitalPillName = styled ( 'div' ) < { status : PerformanceScore } > `
0 commit comments