Skip to content

Commit 59dd764

Browse files
authored
fix(tracemetrics): Show metrics on trace view (#103064)
We changed the 'count' aggregate, so need to update it. Also we should use timestamp when querying for now (and update trace-meta later).
1 parent 3df2736 commit 59dd764

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

static/app/views/performance/newTraceDetails/useInitialTraceMetricData.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ interface UseInitialTraceMetricDataProps {
1717
enabled?: boolean;
1818
}
1919

20+
const COUNT_FIELD = `count(${TraceMetricKnownFieldKey.METRIC_NAME})`;
21+
2022
interface TraceMetricCountResult {
2123
data: Array<{
22-
'count()': number;
24+
[COUNT_FIELD]: number;
2325
}>;
2426
}
2527

@@ -39,7 +41,7 @@ function traceMetricCountQueryKey({
3941

4042
const query: Record<string, string | string[] | number[]> = {
4143
dataset: DiscoverDatasets.TRACEMETRICS,
42-
field: ['count()'],
44+
field: [COUNT_FIELD],
4345
query: searchValue.formatString(),
4446
referrer: 'api.trace-details.initial-metric-data',
4547
};
@@ -48,15 +50,14 @@ function traceMetricCountQueryKey({
4850
query.project = projectIds.map(String);
4951
}
5052

51-
// Use the period from trace query params
52-
if (queryParams.statsPeriod) {
53-
query.statsPeriod = queryParams.statsPeriod;
54-
} else if (queryParams.start && queryParams.end) {
55-
query.start = queryParams.start;
56-
query.end = queryParams.end;
57-
} else {
58-
// Default fallback
59-
query.statsPeriod = '24h';
53+
if (queryParams.timestamp) {
54+
// Use the timestamp to set an interval of +/- 1 days.
55+
query.start = new Date(
56+
queryParams.timestamp * 1000 - 24 * 60 * 60 * 1000
57+
).toISOString();
58+
query.end = new Date(
59+
queryParams.timestamp * 1000 + 24 * 60 * 60 * 1000
60+
).toISOString();
6061
}
6162

6263
return [`/organizations/${orgSlug}/events/`, {query}];
@@ -99,7 +100,7 @@ export function useInitialTraceMetricData({
99100
});
100101

101102
const metricsData = useMemo(() => {
102-
const count = result.data?.data?.[0]?.['count()'] ?? 0;
103+
const count = result.data?.data?.[0]?.[COUNT_FIELD] ?? 0;
103104
return {count};
104105
}, [result.data]);
105106

0 commit comments

Comments
 (0)