Skip to content

Commit 0478932

Browse files
JoshFergegeorge-sentry
authored andcommitted
feat(seer): Record agent_handoff analytics in launch_coding_agents_for_run (#112516)
## Summary - Adds `ai.autofix.agent_handoff` analytics event to `launch_coding_agents_for_run`, which was previously only recorded in `trigger_coding_agent_handoff` (on-completion hook path) - Adds a `referrer` parameter to distinguish the source: `api.organization_coding_agents` (user-initiated from UI), `seer_rpc.trigger_coding_agent_launch` (seer-initiated), or the existing `autofix.on_completion_hook` (automation) - This ensures all coding agent launches (Cursor, Claude Code, GitHub Copilot) are tracked in BigQuery regardless of trigger path ## Test plan - [ ] Verify existing tests pass - [ ] Confirm `ai.autofix.agent_handoff` events appear in BigQuery with the new referrer values after deploy Agent transcript: https://claudescope.sentry.dev/share/K0dXID_ySuOGsHj7b4N5JYUuP88VYoij1v1UHwMd8CA
1 parent 168acdc commit 0478932

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

src/sentry/analytics/events/autofix_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AiAutofixPrCreatedCompletedEvent(AiAutofixPhaseEvent):
7272
@analytics.eventclass("ai.autofix.agent_handoff")
7373
class AiAutofixAgentHandoffEvent(AiAutofixPhaseEvent):
7474
coding_agent: str | None
75+
initiator: str | None = None
7576

7677

7778
analytics.register(AiAutofixRootCauseStartedEvent)

src/sentry/integrations/api/endpoints/organization_coding_agents.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def post(self, request: Request, organization: Organization) -> Response:
153153
trigger_source=trigger_source,
154154
instruction=instruction,
155155
user_id=request.user.id,
156+
initiator="user",
156157
)
157158

158159
successes = results["successes"]

src/sentry/seer/autofix/autofix_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def trigger_coding_agent_handoff(
576576
group_id=group.id,
577577
referrer=referrer.value,
578578
coding_agent=coding_agent_name,
579+
initiator="automation",
579580
)
580581
)
581582

src/sentry/seer/autofix/coding_agent.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from requests import HTTPError
1212
from rest_framework.exceptions import APIException, NotFound, PermissionDenied, ValidationError
1313

14-
from sentry import features
14+
from sentry import analytics, features
1515

1616

1717
class IntegrationNotFound(NotFound):
@@ -30,6 +30,7 @@ class StateReposNotFound(NotFound):
3030
pass
3131

3232

33+
from sentry.analytics.events.autofix_events import AiAutofixAgentHandoffEvent
3334
from sentry.constants import ENABLE_SEER_CODING_DEFAULT, ObjectStatus
3435
from sentry.integrations.claude_code.integration import (
3536
ClaudeCodeIntegrationMetadata,
@@ -419,6 +420,7 @@ def launch_coding_agents_for_run(
419420
trigger_source: AutofixTriggerSource = AutofixTriggerSource.SOLUTION,
420421
instruction: str | None = None,
421422
user_id: int | None = None,
423+
initiator: str | None = None,
422424
) -> dict[str, list]:
423425
"""
424426
Launch coding agents for an autofix run.
@@ -513,6 +515,18 @@ def launch_coding_agents_for_run(
513515
},
514516
)
515517

518+
coding_agent_name = provider or (integration.provider if integration else None)
519+
analytics.record(
520+
AiAutofixAgentHandoffEvent(
521+
organization_id=organization.id,
522+
project_id=autofix_state.request.project_id,
523+
group_id=autofix_state.request.issue["id"],
524+
referrer=None,
525+
coding_agent=coding_agent_name,
526+
initiator=initiator,
527+
)
528+
)
529+
516530
return results
517531

518532

src/sentry/seer/endpoints/seer_rpc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ def trigger_coding_agent_launch(
601601
integration_id=integration_id,
602602
run_id=run_id,
603603
trigger_source=AutofixTriggerSource(trigger_source),
604+
initiator="seer_agent",
604605
)
605606
return {"success": True}
606607
except IntegrationNotFound:

0 commit comments

Comments
 (0)