Skip to content

Conversation

@aliu39
Copy link
Member

@aliu39 aliu39 commented Dec 13, 2025

rpc for our agents to query trace samples (only span samples are supported atm). Works similar to the /explore/traces/ page.

closes AIML-2072: trace table rpc

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 13, 2025
@linear
Copy link

linear bot commented Dec 13, 2025

@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/seer/explorer/tools.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104921      +/-   ##
===========================================
+ Coverage   80.26%    80.43%   +0.17%     
===========================================
  Files        9396      9395       -1     
  Lines      403570    403235     -335     
  Branches    25903     25869      -34     
===========================================
+ Hits       323911    324360     +449     
+ Misses      79224     78440     -784     
  Partials      435       435              

@aliu39 aliu39 marked this pull request as ready for review December 15, 2025 17:27
@aliu39 aliu39 requested a review from a team as a code owner December 15, 2025 17:27
@aliu39 aliu39 enabled auto-merge (squash) December 15, 2025 18:25
stats_period, start, end, default_stats_period="24h"
)

organization = Organization.objects.get(id=organization_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The execute_trace_table_query function does not handle the Organization.DoesNotExist exception, which will cause a crash if an invalid organization ID is passed.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The function execute_trace_table_query calls Organization.objects.get(id=organization_id) without handling the Organization.DoesNotExist exception that can be raised if an invalid organization_id is provided. This is inconsistent with numerous other similar functions within the same file, such as execute_table_query and execute_timeseries_query, which wrap this lookup in a try-except block and return None gracefully. The absence of this exception handling will cause an unhandled exception, leading to a crash in the server process handling the RPC call.

💡 Suggested Fix

Wrap the Organization.objects.get(id=organization_id) call in execute_trace_table_query with a try-except Organization.DoesNotExist block. In the except block, log a warning and return None, mirroring the error handling pattern used by other query functions in the same file.

🤖 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/seer/explorer/tools.py#L314

Potential issue: The function `execute_trace_table_query` calls
`Organization.objects.get(id=organization_id)` without handling the
`Organization.DoesNotExist` exception that can be raised if an invalid `organization_id`
is provided. This is inconsistent with numerous other similar functions within the same
file, such as `execute_table_query` and `execute_timeseries_query`, which wrap this
lookup in a `try-except` block and return `None` gracefully. The absence of this
exception handling will cause an unhandled exception, leading to a crash in the server
process handling the RPC call.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7539742

@aliu39 aliu39 merged commit b48152e into master Dec 15, 2025
67 checks passed
@aliu39 aliu39 deleted the aliu/traces-rpc branch December 15, 2025 18:47
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants