1
- import { Fragment , useContext , useEffect } from 'react' ;
1
+ import { Fragment , useEffect } from 'react' ;
2
2
import styled from '@emotion/styled' ;
3
3
4
4
import { analyzeFramesForRootCause } from 'sentry/components/events/interfaces/analyzeFrames' ;
5
5
import { StackTraceContent } from 'sentry/components/events/interfaces/crashContent/stackTrace' ;
6
6
import NoStackTraceMessage from 'sentry/components/events/interfaces/noStackTraceMessage' ;
7
7
import getThreadStacktrace from 'sentry/components/events/interfaces/threads/threadSelector/getThreadStacktrace' ;
8
- import { getThreadById , inferPlatform } from 'sentry/components/events/interfaces/utils' ;
8
+ import {
9
+ getEventTimestampInSeconds ,
10
+ getThreadById ,
11
+ inferPlatform ,
12
+ } from 'sentry/components/events/interfaces/utils' ;
9
13
import GlobalSelectionLink from 'sentry/components/globalSelectionLink' ;
10
14
import ShortId from 'sentry/components/group/inboxBadges/shortId' ;
11
15
import ProjectBadge from 'sentry/components/idBadge/projectBadge' ;
@@ -16,10 +20,12 @@ import type {Organization} from 'sentry/types/organization';
16
20
import { StackView } from 'sentry/types/stacktrace' ;
17
21
import { defined } from 'sentry/utils' ;
18
22
import { trackAnalytics } from 'sentry/utils/analytics' ;
19
- import { QuickTraceContext } from 'sentry/utils/performance/quickTrace/quickTraceContext' ;
20
23
import useProjects from 'sentry/utils/useProjects' ;
21
24
import { SectionKey } from 'sentry/views/issueDetails/streamline/context' ;
22
25
import { InterimSection } from 'sentry/views/issueDetails/streamline/interimSection' ;
26
+ import { useIssuesTraceTree } from 'sentry/views/performance/newTraceDetails/traceApi/useIssuesTraceTree' ;
27
+ import { useTrace } from 'sentry/views/performance/newTraceDetails/traceApi/useTrace' ;
28
+ import { isEAPTraceOccurrence } from 'sentry/views/performance/newTraceDetails/traceGuards' ;
23
29
24
30
enum AnrRootCauseAllowlist {
25
31
PERFORMANCE_FILE_IO_MAIN_THREAD_GROUP_TYPE = 1008 ,
@@ -32,7 +38,16 @@ interface Props {
32
38
}
33
39
34
40
export function AnrRootCause ( { event, organization} : Props ) {
35
- const quickTrace = useContext ( QuickTraceContext ) ;
41
+ const traceSlug = event . contexts . trace ?. trace_id ?? '' ;
42
+
43
+ const trace = useTrace ( {
44
+ timestamp : getEventTimestampInSeconds ( event ) ,
45
+ traceSlug,
46
+ limit : 10000 ,
47
+ } ) ;
48
+ const tree = useIssuesTraceTree ( { trace, replay : null } ) ;
49
+ const traceNode = tree . root . children [ 0 ] ;
50
+
36
51
const { projects} = useProjects ( ) ;
37
52
38
53
const anrCulprit = analyzeFramesForRootCause ( event ) ;
@@ -49,20 +64,19 @@ export function AnrRootCause({event, organization}: Props) {
49
64
} ) ;
50
65
} , [ anrCulprit , organization , event ?. groupID ] ) ;
51
66
52
- const noPerfIssueOnTrace =
53
- ! quickTrace ||
54
- quickTrace . error ||
55
- quickTrace . trace === null ||
56
- quickTrace . trace . length === 0 ||
57
- quickTrace . trace [ 0 ] ?. performance_issues ? .length === 0 ;
67
+ if ( tree . type === 'loading' || tree . type === 'error' ) {
68
+ return null ;
69
+ }
70
+
71
+ const occurrences = Array . from ( traceNode ?. occurrences ?? [ ] ) ;
72
+ const noPerfIssueOnTrace = occurrences . length === 0 ;
58
73
59
74
if ( noPerfIssueOnTrace && ! anrCulprit ) {
60
75
return null ;
61
76
}
62
77
63
- const potentialAnrRootCause = quickTrace ?. trace ?. [ 0 ] ?. performance_issues ?. filter (
64
- issue =>
65
- Object . values ( AnrRootCauseAllowlist ) . includes ( issue . type as AnrRootCauseAllowlist )
78
+ const potentialAnrRootCause = occurrences . filter ( issue =>
79
+ Object . values ( AnrRootCauseAllowlist ) . includes ( issue . type as AnrRootCauseAllowlist )
66
80
) ;
67
81
68
82
const helpText =
@@ -119,28 +133,34 @@ export function AnrRootCause({event, organization}: Props) {
119
133
type = { SectionKey . SUSPECT_ROOT_CAUSE }
120
134
help = { helpText }
121
135
>
122
- { potentialAnrRootCause ?. map ( issue => {
123
- const project = projects . find ( p => p . id === issue . project_id . toString ( ) ) ;
136
+ { potentialAnrRootCause ?. map ( occurence => {
137
+ const project = projects . find ( p => p . id === occurence . project_id . toString ( ) ) ;
138
+ const title = isEAPTraceOccurrence ( occurence )
139
+ ? occurence . description
140
+ : occurence . title ;
141
+ const shortId = isEAPTraceOccurrence ( occurence )
142
+ ? occurence . short_id
143
+ : occurence . issue_short_id ;
124
144
return (
125
- < IssueSummary key = { issue . issue_id } >
145
+ < IssueSummary key = { occurence . issue_id } >
126
146
< Title >
127
147
< TitleWithLink
128
148
to = { {
129
- pathname : `/organizations/${ organization . id } /issues/${ issue . issue_id } /${
130
- issue . event_id ? `events/${ issue . event_id } /` : ''
149
+ pathname : `/organizations/${ organization . id } /issues/${ occurence . issue_id } /${
150
+ occurence . event_id ? `events/${ occurence . event_id } /` : ''
131
151
} `,
132
152
} }
133
153
>
134
- { issue . title }
154
+ { title }
135
155
< Fragment >
136
156
< Spacer />
137
- < Subtitle title = { issue . culprit } > { issue . culprit } </ Subtitle >
157
+ < Subtitle title = { occurence . culprit } > { occurence . culprit } </ Subtitle >
138
158
</ Fragment >
139
159
</ TitleWithLink >
140
160
</ Title >
141
- { issue . issue_short_id && (
161
+ { shortId && (
142
162
< ShortId
143
- shortId = { issue . issue_short_id }
163
+ shortId = { shortId }
144
164
avatar = {
145
165
project && < ProjectBadge project = { project } hideName avatarSize = { 12 } />
146
166
}
0 commit comments