-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(llm-detection): Refactor Seer integration to fetch traces via RPC #104485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
|
|
||
| class EvidenceTraceData(BaseModel): | ||
| class EvidenceTraceData(BaseModel): # hate this name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any naming suggestions?
|
|
||
| NUM_TRANSACTIONS_TO_PROCESS = 20 | ||
| LOWER_SPAN_LIMIT = 20 | ||
| UPPER_SPAN_LIMIT = 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these will be handled on the seer side
c36bdc3 to
f36abaf
Compare
| class EvidenceTraceData(BaseModel): # hate this name | ||
| trace_id: str | ||
| project_id: int | ||
| transaction_name: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the transaction name in addition to the trace_id when fetching the EAPTrace? or is this just so we still have access to the transaction name for our own things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great q - transaction name is now just context data that we pass to seer, and seer passes back in the detected issue, because we need it to create the issue.
the EAPTrace only needs trace_id + org_id
f36abaf to
52a714f
Compare
52a714f to
d0ece3c
Compare
| organization_id=organization_id, | ||
| response_data=response.data.decode("utf-8"), | ||
| error_message=str(e), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing pydantic.ValidationError in exception handler
The exception handler catches (ValueError, TypeError) but IssueDetectionResponse.parse_obj() raises pydantic.ValidationError when the Seer response doesn't match the expected schema. Since the DetectedIssue model now requires trace_id and transaction_name fields that Seer must pass back, if Seer fails to return these fields or returns them with incorrect types, the pydantic.ValidationError will propagate uncaught instead of being wrapped in LLMIssueDetectionError. The codebase correctly catches pydantic.ValidationError elsewhere when using parse_obj.
| spans: list[Span] | ||
|
|
||
|
|
||
| class EvidenceTraceData(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that we aren't passing any real trace data here, we can use whatever name we want
| if not has_access: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unhandled Project.DoesNotExist exception when fetching project from cache, leading to task crashes.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The Project.objects.get_from_cache(id=project_id) call at src/sentry/tasks/llm_issue_detection/detection.py:224 lacks error handling for Project.DoesNotExist. If a project is deleted after run_llm_issue_detection() dispatches the subtask but before detect_llm_issues_for_project() executes, the task will crash with an unhandled Project.DoesNotExist exception. This is inconsistent with trace_data.py in the same PR, which explicitly handles this exception.
💡 Suggested Fix
Wrap the Project.objects.get_from_cache() call in a try-except Project.DoesNotExist block, log the error, and return early to gracefully handle missing projects.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/sentry/tasks/llm_issue_detection/detection.py#L224-L225
Potential issue: The `Project.objects.get_from_cache(id=project_id)` call at
`src/sentry/tasks/llm_issue_detection/detection.py:224` lacks error handling for
`Project.DoesNotExist`. If a project is deleted after `run_llm_issue_detection()`
dispatches the subtask but before `detect_llm_issues_for_project()` executes, the task
will crash with an unhandled `Project.DoesNotExist` exception. This is inconsistent with
`trace_data.py` in the same PR, which explicitly handles this exception.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5916674
| if processed_count >= NUM_TRANSACTIONS_TO_PROCESS: | ||
| break | ||
| seer_request = { | ||
| "telemetry": [{**trace.dict(), "kind": "trace"} for trace in evidence_traces], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like we could use better variable names here since it's just the id/name instead of an actual trace now
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #104485 +/- ##
========================================
Coverage 80.53% 80.53%
========================================
Files 9350 9350
Lines 400099 400078 -21
Branches 25660 25660
========================================
- Hits 322216 322201 -15
+ Misses 77415 77409 -6
Partials 468 468 |
Problem
The LLM issue detection task was fetching full span data for every trace in Sentry, then sending bits of that telemetry to Seer in individual requests. We want to use EAPTrace instead which would include much more data in a format better optimized for llm analysis. This requires a significant restructuring of the request/response formats between this task and its seer endpoint.
There was also a lil bug in how we were selecting traces for each transaction - cleared that up and introduced a tiny bit of variation to trace selection logic.
Solution
Changed the request/response flow so Sentry sends only trace IDs to Seer in a single bundled request. Now, Seer fetches the full
EAPTracedata itself via Sentry's existingget_trace_waterfallRPC endpoint and uses that as the input for llm detection.Changes to Sentry → Seer Request
Before:
trace_id,project_id,transaction_name,total_spans,spans: list[Span]After:
trace_idand normalizedtransaction_nameEAPTracedata via RPCChanges to Seer → Sentry Response
Updated
DetectedIssuemodel to include context fields:trace_id: str- which trace the issue was found intransaction_name: str- normalized transaction nameTrace Selection Logic
sum(span.duration)over 30-minute windowBreaking Changes
This is a breaking change to the Seer integration. Deployment requires:
issue-detection.llm-detection.enabled = false)This will not impact any customers.