Skip to content

Conversation

@Zylphrex
Copy link
Member

This isn't needed anymore because we parse the condition from the aggregation.

This isn't needed anymore because we parse the condition from the aggregation.
@Zylphrex Zylphrex requested a review from a team as a code owner November 14, 2025 19:21
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 14, 2025
Comment on lines 66 to 72
enabled,
limit,
traceMetric,
queryExtras: {
...queryExtras,
traceMetric,
},
queryExtras,
},
queryOptions: {
canTriggerHighAccuracy,
Copy link

Choose a reason for hiding this comment

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

Bug: useMetricAggregatesTable.tsx fails to add traceMetric filters (metric.name, metric.type) to the search query, leading to unfiltered aggregate results.
Severity: CRITICAL | Confidence: 0.95

🔍 Detailed Analysis

In useMetricAggregatesTable.tsx, the traceMetric parameters were removed from queryExtras, but the corresponding metric filters (TraceMetricKnownFieldKey.METRIC_NAME, TraceMetricKnownFieldKey.METRIC_TYPE) were not added to the search query. The backend expects explicit query parameters for metric filtering, not just parsing from aggregation expressions. Consequently, the aggregates table will return data for all metrics instead of filtering to the selected traceMetric, leading to incorrect and misleading results.

💡 Suggested Fix

Update useMetricAggregatesTable.tsx to add traceMetric.name and traceMetric.type as filters to the MutableSearch object when traceMetric is present, mirroring the implementation in useMetricSamplesTable.tsx.

🤖 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: static/app/views/explore/metrics/hooks/useMetricAggregatesTable.tsx#L66-L72

Potential issue: In `useMetricAggregatesTable.tsx`, the `traceMetric` parameters were
removed from `queryExtras`, but the corresponding metric filters
(`TraceMetricKnownFieldKey.METRIC_NAME`, `TraceMetricKnownFieldKey.METRIC_TYPE`) were
not added to the search query. The backend expects explicit query parameters for metric
filtering, not just parsing from aggregation expressions. Consequently, the aggregates
table will return data for all metrics instead of filtering to the selected
`traceMetric`, leading to incorrect and misleading results.

Did we get this right? 👍 / 👎 to inform future reviews.

Reference_id: 2694881

@codecov
Copy link

codecov bot commented Nov 14, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
12586 1 12585 10
View the top 1 failed test(s) by shortest run time
useMetricSamplesTable simple usage
Stack Traces | 0.031s run time
Error: expect(jest.fn()).toHaveBeenCalledWith(...expected)

Expected: "....../organizations/org-slug/events/", ObjectContaining {"query": ObjectContaining {"caseInsensitive": undefined, "dataset": "tracemetrics", "disableAggregateExtrapolation": undefined, "environment": ["prod"], "field": ["id", "project.id", "trace", "span_id", "sentry.span_id", "metric.type", "metric.name", "timestamp"], "metricName": "test.metric", "metricType": "counter", "orderby": ["-timestamp"], "per_page": 50, "project": ["1", "2"], "query": "", "referrer": "api.explore.metric-samples-table", "sampling": "NORMAL", "sort": "-timestamp"}}
Received: "....../organizations/org-slug/events/", {"data": undefined, "error": [Function error], "headers": undefined, "host": undefined, "method": "GET", "query": {"caseInsensitive": undefined, "dataset": "tracemetrics", "disableAggregateExtrapolation": undefined, "end": "2017-10-17T02:41:20.000", "environment": ["prod"], "field": ["id", "project.id", "trace", "span_id", "sentry.span_id", "metric.type", "metric.name", "timestamp"], "orderby": ["-timestamp"], "per_page": 50, "project": ["1", "2"], "query": "metric.name:test.metric metric.type:counter", "referrer": "api.explore.metric-samples-table", "sampling": "NORMAL", "sort": "-timestamp", "start": "2017-10-16T02:41:20.000"}, "success": [Function success]}

Number of calls: 1
    at Object.toHaveBeenCalledWith (.../metrics/hooks/useMetricSamplesTable.spec.tsx:128:25)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Missing Metric Filters Compromise Data Integrity

The metric filters are no longer being sent to the backend. The old code explicitly passed metricName and metricType as query parameters in useSortedTimeSeries, but the diff removes these without adding the metric filters to the search query. Unlike useMetricSamplesTableImpl, which adds metric filters using addFilterValue(), this change leaves metric filtering information missing. This will cause timeseries queries to return incorrect data without the intended metric name and type filtering.

static/app/views/explore/metrics/hooks/useMetricTimeseries.tsx#L42-L78

}
interface UseMetricTimeseriesImplOptions extends UseMetricTimeseriesOptions {
queryExtras?: RPCQueryExtras;
}
function useMetricTimeseriesImpl({
traceMetric,
queryExtras,
enabled,
}: UseMetricTimeseriesImplOptions) {
const visualize = useMetricVisualize();
const groupBys = useQueryParamsGroupBys();
const [interval] = useChartInterval();
const topEvents = useTopEvents();
const search = useQueryParamsSearch();
const sortBys = useQueryParamsAggregateSortBys();
const timeseriesResult = useSortedTimeSeries(
{
search,
yAxis: [visualize.yAxis],
interval,
fields: [...groupBys, visualize.yAxis],
enabled: enabled && Boolean(traceMetric.name),
topEvents,
orderby: sortBys.map(formatSort),
...queryExtras,
},
'api.explore.metrics-stats',
DiscoverDatasets.TRACEMETRICS
);
return {
result: timeseriesResult,
};
}

Fix in Cursor Fix in Web


@Zylphrex Zylphrex merged commit 677ac26 into master Nov 14, 2025
48 checks passed
@Zylphrex Zylphrex deleted the txiao/chore/remove-unneeded-trace-metric-from-queries branch November 14, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants