|
8 | 8 | from pydantic import BaseModel |
9 | 9 | from rest_framework.exceptions import PermissionDenied |
10 | 10 |
|
| 11 | +from sentry import analytics |
| 12 | +from sentry.analytics.events.autofix_events import ( |
| 13 | + AiAutofixAgentHandoffEvent, |
| 14 | + AiAutofixCodeChangesCompletedEvent, |
| 15 | + AiAutofixCodeChangesStartedEvent, |
| 16 | + AiAutofixImpactAssessmentCompletedEvent, |
| 17 | + AiAutofixImpactAssessmentStartedEvent, |
| 18 | + AiAutofixPhaseEvent, |
| 19 | + AiAutofixPrCreatedStartedEvent, |
| 20 | + AiAutofixRootCauseCompletedEvent, |
| 21 | + AiAutofixRootCauseStartedEvent, |
| 22 | + AiAutofixSolutionCompletedEvent, |
| 23 | + AiAutofixSolutionStartedEvent, |
| 24 | + AiAutofixTriageCompletedEvent, |
| 25 | + AiAutofixTriageStartedEvent, |
| 26 | +) |
11 | 27 | from sentry.constants import ENABLE_SEER_CODING_DEFAULT |
12 | 28 | from sentry.seer.autofix.artifact_schemas import ( |
13 | 29 | ImpactAssessmentArtifact, |
@@ -82,34 +98,48 @@ def __init__( |
82 | 98 | artifact_schema: type[BaseModel] | None, |
83 | 99 | prompt_fn: Callable[..., str], |
84 | 100 | enable_coding: bool = False, |
| 101 | + started_event: type[AiAutofixPhaseEvent] | None = None, |
| 102 | + completed_event: type[AiAutofixPhaseEvent] | None = None, |
85 | 103 | ): |
86 | 104 | self.artifact_schema = artifact_schema |
87 | 105 | self.prompt_fn = prompt_fn |
88 | 106 | self.enable_coding = enable_coding |
| 107 | + self.started_event = started_event |
| 108 | + self.completed_event = completed_event |
89 | 109 |
|
90 | 110 |
|
91 | 111 | # Step configurations mapping step to its artifact schema and prompt |
92 | 112 | STEP_CONFIGS: dict[AutofixStep, StepConfig] = { |
93 | 113 | AutofixStep.ROOT_CAUSE: StepConfig( |
94 | 114 | artifact_schema=RootCauseArtifact, |
95 | 115 | prompt_fn=root_cause_prompt, |
| 116 | + started_event=AiAutofixRootCauseStartedEvent, |
| 117 | + completed_event=AiAutofixRootCauseCompletedEvent, |
96 | 118 | ), |
97 | 119 | AutofixStep.SOLUTION: StepConfig( |
98 | 120 | artifact_schema=SolutionArtifact, |
99 | 121 | prompt_fn=solution_prompt, |
| 122 | + started_event=AiAutofixSolutionStartedEvent, |
| 123 | + completed_event=AiAutofixSolutionCompletedEvent, |
100 | 124 | ), |
101 | 125 | AutofixStep.CODE_CHANGES: StepConfig( |
102 | 126 | artifact_schema=None, # Code changes read from file_patches |
103 | 127 | prompt_fn=code_changes_prompt, |
104 | 128 | enable_coding=True, |
| 129 | + started_event=AiAutofixCodeChangesStartedEvent, |
| 130 | + completed_event=AiAutofixCodeChangesCompletedEvent, |
105 | 131 | ), |
106 | 132 | AutofixStep.IMPACT_ASSESSMENT: StepConfig( |
107 | 133 | artifact_schema=ImpactAssessmentArtifact, |
108 | 134 | prompt_fn=impact_assessment_prompt, |
| 135 | + started_event=AiAutofixImpactAssessmentStartedEvent, |
| 136 | + completed_event=AiAutofixImpactAssessmentCompletedEvent, |
109 | 137 | ), |
110 | 138 | AutofixStep.TRIAGE: StepConfig( |
111 | 139 | artifact_schema=TriageArtifact, |
112 | 140 | prompt_fn=triage_prompt, |
| 141 | + started_event=AiAutofixTriageStartedEvent, |
| 142 | + completed_event=AiAutofixTriageCompletedEvent, |
113 | 143 | ), |
114 | 144 | } |
115 | 145 |
|
@@ -215,6 +245,16 @@ def trigger_autofix_explorer( |
215 | 245 | """ |
216 | 246 |
|
217 | 247 | config = STEP_CONFIGS[step] |
| 248 | + |
| 249 | + if config.started_event is not None: |
| 250 | + analytics.record( |
| 251 | + config.started_event( |
| 252 | + organization_id=group.organization.id, |
| 253 | + project_id=group.project_id, |
| 254 | + group_id=group.id, |
| 255 | + referrer=referrer.value, |
| 256 | + ) |
| 257 | + ) |
218 | 258 | client = get_autofix_explorer_client( |
219 | 259 | group, |
220 | 260 | intelligence_level=intelligence_level, |
@@ -500,6 +540,15 @@ def trigger_coding_agent_handoff( |
500 | 540 | auto_create_pr=auto_create_pr, |
501 | 541 | ) |
502 | 542 |
|
| 543 | + analytics.record( |
| 544 | + AiAutofixAgentHandoffEvent( |
| 545 | + organization_id=group.organization.id, |
| 546 | + project_id=group.project_id, |
| 547 | + group_id=group.id, |
| 548 | + referrer=referrer.value, |
| 549 | + ) |
| 550 | + ) |
| 551 | + |
503 | 552 | metrics.incr( |
504 | 553 | "autofix.explorer.trigger", |
505 | 554 | tags={"step": "coding_agent_handoff", "referrer": referrer.value}, |
@@ -532,6 +581,15 @@ def trigger_push_changes( |
532 | 581 | if group_id != group.id: |
533 | 582 | raise SeerPermissionError("Unknown run id for group") |
534 | 583 |
|
| 584 | + analytics.record( |
| 585 | + AiAutofixPrCreatedStartedEvent( |
| 586 | + organization_id=group.organization.id, |
| 587 | + project_id=group.project_id, |
| 588 | + group_id=group.id, |
| 589 | + referrer=referrer.value, |
| 590 | + ) |
| 591 | + ) |
| 592 | + |
535 | 593 | client.push_changes( |
536 | 594 | run_id, |
537 | 595 | repo_name=repo_name, |
|
0 commit comments