fix(seer): Use count(value) in tracemetrics query for metric metadata#113616
Merged
isaacwang-sentry merged 1 commit intoApr 22, 2026
Merged
Conversation
The get_metric_metadata RPC handler passed zero-arg count() as an aggregate field on the tracemetrics dataset. The tracemetrics parser requires count() to take an attribute argument, so every call since the handler merged has returned events_query_failed from the events-layer parser. The bug wasn't caught in CI because the existing tests mocked sentry.api.client wholesale and never exercised the real parser. Changes: - Replace count() with count(value) in the field list, sort, and row lookup. - Extend logger.exception extras with ApiError.status_code and a truncated body prefix so future flakes are debuggable from logs without a new deploy. - Add TestGetMetricMetadataIntegration that persists real TraceItems and hits the handler end-to-end; this is the shape of test that would have caught the original bug. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
isaacwang-sentry
marked this pull request as ready for review
April 21, 2026 22:46
sehr-m
approved these changes
Apr 21, 2026
isaacwang-sentry
deleted the
isaac/fix/seer-metric-metadata-count-aggregate
branch
April 22, 2026 16:49
3 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fix the
get_metric_metadataRPC handler to usecount(value)instead of zero-argcount()in its tracemetrics query.The
tracemetricsdataset parser requirescount()to take an attribute argument. Zero-argcount()parse-fails at the events layer withstatus=400 body={'detail': 'Invalid number of arguments for count, was expecting 1 arguments', 'code': 'parse_error'}. Every call to this handler since it was merged in #113462 has been returningevents_query_failed— the Seer assisted-query metrics agent has never once received real candidates from this tool and has been silently falling back toget_field_valuesprobes instead.The bug wasn't caught because the existing tests mocked
sentry.api.clientwholesale and never exercised the real parser. This PR also addsTestGetMetricMetadataIntegration, which persists realTraceItems and hits the handler end-to-end viaTraceMetricsTestCase— this is the shape of test that would have caught the original bug, and will catch future regressions in the aggregate-function shape.While here, the
ApiErrorcatch block now attachesstatus_codeand a 500-char body prefix to itslogger.exceptionextras so future flakes are debuggable from logs without a new deploy cycle.Reproduction (before this PR, on prod):
returns
{"candidates": [], "has_more": false, "error": "events_query_failed"}on every substring, 25/25 tries. After this PR the same request returns populated candidates.Refs #113462