chore(llm-detection): Store trace id, category, and subcategory in issue metadata#109430
Open
chore(llm-detection): Store trace id, category, and subcategory in issue metadata#109430
Conversation
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.
Comment on lines
+193
to
+197
| "metadata": { | ||
| "trace_id": trace_id, | ||
| "category": detected_issue.category, | ||
| "subcategory": detected_issue.subcategory, | ||
| }, |
Contributor
There was a problem hiding this comment.
Bug: The metadata dictionary from the LLM detection task is overwritten in the occurrence consumer, losing the trace_id, category, and subcategory fields.
Severity: HIGH
Suggested Fix
In occurrence_consumer.py, modify the logic to merge the existing metadata with the new title field instead of overwriting it. Retrieve the existing metadata from the event payload and update it with the title, rather than creating a new dictionary.
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#L193-L197
Potential issue: In `detection.py`, an event is created with a `metadata` dictionary
containing `trace_id`, `category`, and `subcategory`. This event is sent via Kafka to
the occurrence consumer. However, in `occurrence_consumer.py`, the `_get_kwargs`
function unconditionally overwrites the `metadata` field with a new dictionary
containing only the `issue_title`. As a result, the original metadata fields
(`trace_id`, `category`, `subcategory`) are lost when the event is saved. This prevents
the ability to query for LLM-detected issues by `trace_id` or access the other metadata
fields from the database.
Did we get this right? 👍 / 👎 to inform future reviews.
1a6ce30 to
711f1a1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This feels hacky, but I'm wondering if it's possible to include these additional fields on the issue, without displaying them on the frontend, just to make issue quality analysis queries easier.
Summary
category,subcategory, andtrace_idto the event metadata for LLM-detected issuessentry_groupedmessage.data["metadata"]trace_idcategory,subcategorycan now be accessed from the db without having to cross-reference logs