Browse Source

feat(suspect-commits): Add suspect commit calculation type to frontend analytics (#59331)

- Remove `loading` from the analytics, don't think it was necessary (and
certainly not descriptive)
- Fixed `num_suspect_commits` to use the correct number (commits instead
of committers)
- Added `suspect_commit_calculation` to distinguish between suspect
commits created with the release method vs the SCM method
Malachi Willey 1 year ago
parent
commit
b847ef5d48

+ 17 - 13
static/app/components/events/eventCause.tsx

@@ -26,17 +26,12 @@ interface Props {
 export function EventCause({group, eventId, project, commitRow: CommitRow}: Props) {
   const organization = useOrganization();
   const [isExpanded, setIsExpanded] = useState(false);
-  const {data, isLoading} = useCommitters({
+  const {data} = useCommitters({
     eventId,
     projectSlug: project.slug,
   });
   const committers = data?.committers ?? [];
 
-  useRouteAnalyticsParams({
-    fetching: isLoading,
-    num_suspect_commits: committers.length,
-  });
-
   function getUniqueCommitsWithAuthors() {
     // Get a list of commits with author information attached
     const commitsWithAuthors = flatMap(committers, ({commits, author}) =>
@@ -50,29 +45,38 @@ export function EventCause({group, eventId, project, commitRow: CommitRow}: Prop
     return uniqBy(commitsWithAuthors, commit => commit.id);
   }
 
+  const commits = getUniqueCommitsWithAuthors();
+
+  useRouteAnalyticsParams({
+    num_suspect_commits: commits.length,
+    suspect_commit_calculation: commits[0]?.suspectCommitType ?? 'no suspect commit',
+  });
+
   if (!committers.length) {
     return null;
   }
 
-  const handlePullRequestClick = () => {
+  const handlePullRequestClick = (commit: Commit, commitIndex: number) => {
     trackAnalytics('issue_details.suspect_commits.pull_request_clicked', {
       organization,
       project_id: parseInt(project.id as string, 10),
+      suspect_commit_calculation: commit.suspectCommitType ?? 'unknown',
+      suspect_commit_index: commitIndex,
       ...getAnalyticsDataForGroup(group),
     });
   };
 
-  const handleCommitClick = (commit: Commit) => {
+  const handleCommitClick = (commit: Commit, commitIndex: number) => {
     trackAnalytics('issue_details.suspect_commits.commit_clicked', {
       organization,
       project_id: parseInt(project.id as string, 10),
       has_pull_request: commit.pullRequest?.id !== undefined,
+      suspect_commit_calculation: commit.suspectCommitType ?? 'unknown',
+      suspect_commit_index: commitIndex,
       ...getAnalyticsDataForGroup(group),
     });
   };
 
-  const commits = getUniqueCommitsWithAuthors();
-
   const commitHeading = tn('Suspect Commit', 'Suspect Commits (%s)', commits.length);
 
   return (
@@ -97,12 +101,12 @@ export function EventCause({group, eventId, project, commitRow: CommitRow}: Prop
         )}
       </CauseHeader>
       <StyledPanel>
-        {commits.slice(0, isExpanded ? 100 : 1).map(commit => (
+        {commits.slice(0, isExpanded ? 100 : 1).map((commit, commitIndex) => (
           <CommitRow
             key={commit.id}
             commit={commit}
-            onCommitClick={handleCommitClick}
-            onPullRequestClick={handlePullRequestClick}
+            onCommitClick={() => handleCommitClick(commit, commitIndex)}
+            onPullRequestClick={() => handlePullRequestClick(commit, commitIndex)}
           />
         ))}
       </StyledPanel>

+ 6 - 1
static/app/utils/analytics/workflowAnalyticsEvents.tsx

@@ -112,8 +112,13 @@ export type TeamInsightsEventParameters = {
   };
   'issue_details.suspect_commits.commit_clicked': IssueDetailsWithAlert & {
     has_pull_request: boolean;
+    suspect_commit_calculation: string;
+    suspect_commit_index: number;
+  };
+  'issue_details.suspect_commits.pull_request_clicked': IssueDetailsWithAlert & {
+    suspect_commit_calculation: string;
+    suspect_commit_index: number;
   };
-  'issue_details.suspect_commits.pull_request_clicked': IssueDetailsWithAlert;
   'issue_details.tab_changed': IssueDetailsWithAlert & {
     tab: Tab;
   };

+ 3 - 0
static/app/views/issueDetails/groupDetails.tsx

@@ -621,6 +621,9 @@ function useTrackView({
     trace_status: 'none',
     // Will be updated in GroupDetailsHeader if there are replays
     group_has_replay: false,
+    // Will be updated in EventCause if there are suspect commits
+    num_suspect_commits: -1,
+    suspect_commit_calculation: 'none',
   });
   useDisableRouteAnalytics(!group || !event || !project);
 }