@@ -22,6 +22,9 @@ import {
22
22
sortedFlags ,
23
23
} from 'sentry/components/events/featureFlags/utils' ;
24
24
import useDrawer from 'sentry/components/globalDrawer' ;
25
+ import { useGroupSuspectFlagScores } from 'sentry/components/issues/suspect/useGroupSuspectFlagScores' ;
26
+ import useLegacyEventSuspectFlags from 'sentry/components/issues/suspect/useLegacyEventSuspectFlags' ;
27
+ import useSuspectFlagScoreThreshold from 'sentry/components/issues/suspect/useSuspectFlagScoreThreshold' ;
25
28
import { KeyValueData } from 'sentry/components/keyValueData' ;
26
29
import { featureFlagOnboardingPlatforms } from 'sentry/data/platformCategories' ;
27
30
import { IconMegaphone , IconSearch } from 'sentry/icons' ;
@@ -35,10 +38,10 @@ import {useFeedbackForm} from 'sentry/utils/useFeedbackForm';
35
38
import { useLocation } from 'sentry/utils/useLocation' ;
36
39
import useOrganization from 'sentry/utils/useOrganization' ;
37
40
import { SectionKey } from 'sentry/views/issueDetails/streamline/context' ;
38
- import useLegacyEventSuspectFlags from 'sentry/views/issueDetails/streamline/hooks/featureFlags/useLegacyEventSuspectFlags' ;
39
41
import { useOrganizationFlagLog } from 'sentry/views/issueDetails/streamline/hooks/featureFlags/useOrganizationFlagLog' ;
40
42
import { useIssueDetailsEventView } from 'sentry/views/issueDetails/streamline/hooks/useIssueDetailsDiscoverQuery' ;
41
43
import { InterimSection } from 'sentry/views/issueDetails/streamline/interimSection' ;
44
+ import { useEnvironmentsFromUrl } from 'sentry/views/issueDetails/utils' ;
42
45
43
46
export function EventFeatureFlagSection ( props : EventFeatureFlagSectionProps ) {
44
47
return (
@@ -55,6 +58,9 @@ type EventFeatureFlagSectionProps = {
55
58
} ;
56
59
57
60
function BaseEventFeatureFlagList ( { event, group, project} : EventFeatureFlagSectionProps ) {
61
+ const organization = useOrganization ( ) ;
62
+ const environments = useEnvironmentsFromUrl ( ) ;
63
+
58
64
const openForm = useFeedbackForm ( ) ;
59
65
const feedbackButton = openForm ? (
60
66
< Button
@@ -75,11 +81,14 @@ function BaseEventFeatureFlagList({event, group, project}: EventFeatureFlagSecti
75
81
</ Button >
76
82
) : null ;
77
83
84
+ // If we're showing the suspect section at all
85
+ const enableSuspectFlags = organization . features . includes ( 'feature-flag-suspect-flags' ) ;
86
+
78
87
const [ sortBy , setSortBy ] = useState < SortBy > ( SortBy . EVAL_ORDER ) ;
79
88
const [ orderBy , setOrderBy ] = useState < OrderBy > ( OrderBy . NEWEST ) ;
80
89
const { closeDrawer, isDrawerOpen, openDrawer} = useDrawer ( ) ;
81
90
const viewAllButtonRef = useRef < HTMLButtonElement > ( null ) ;
82
- const organization = useOrganization ( ) ;
91
+
83
92
const eventView = useIssueDetailsEventView ( { group} ) ;
84
93
const { data : rawFlagData } = useOrganizationFlagLog ( {
85
94
organization,
@@ -120,22 +129,31 @@ function BaseEventFeatureFlagList({event, group, project}: EventFeatureFlagSecti
120
129
[ organization , queryParams ]
121
130
) ;
122
131
123
- const {
124
- suspectFlags,
125
- isError : isSuspectError ,
126
- isPending : isSuspectPending ,
127
- } = useLegacyEventSuspectFlags ( {
132
+ const { suspectFlags : legacySuspectFlags } = useLegacyEventSuspectFlags ( {
133
+ enabled : ! enableSuspectFlags , // Fallback to the legacy strategy
128
134
organization,
129
135
firstSeen : group . firstSeen ,
130
136
rawFlagData,
131
137
event,
132
138
} ) ;
133
139
140
+ const [ suspectThreshold ] = useSuspectFlagScoreThreshold ( ) ;
141
+ const { data : suspectScores } = useGroupSuspectFlagScores ( {
142
+ groupId : group . id ,
143
+ environment : environments . length ? environments : undefined ,
144
+ enabled : enableSuspectFlags ,
145
+ } ) ;
146
+
134
147
const suspectFlagNames : Set < string > = useMemo ( ( ) => {
135
- return isSuspectError || isSuspectPending
136
- ? new Set ( )
137
- : new Set ( suspectFlags . map ( f => f . flag ) ) ;
138
- } , [ isSuspectError , isSuspectPending , suspectFlags ] ) ;
148
+ if ( enableSuspectFlags ) {
149
+ return new Set (
150
+ suspectScores ?. data
151
+ . filter ( score => score . score >= suspectThreshold )
152
+ . map ( score => score . flag )
153
+ ) ;
154
+ }
155
+ return new Set ( legacySuspectFlags . map ( f => f . flag ) ) ;
156
+ } , [ enableSuspectFlags , legacySuspectFlags , suspectScores ?. data , suspectThreshold ] ) ;
139
157
140
158
const eventFlags : Array < Required < FeatureFlag > > = useMemo ( ( ) => {
141
159
// At runtime there's no type guarantees on the event flags. So we have to
0 commit comments