Skip to content

Commit d05f67d

Browse files
authored
fix(insights): use correct meta in llm monitoring pipelines table (#92328)
llm monitoring table makes multiple requests and joins their data to create a `rows` array for the `pipelines` table. Because we make multiple requests, we should combine the meta so that the `fieldRenderer` is able to correctly lookup the `meta`
1 parent 23efd6f commit d05f67d

File tree

4 files changed

+96
-21
lines changed

4 files changed

+96
-21
lines changed

static/app/views/insights/cache/views/cacheLandingPage.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
3636
import {useHasFirstSpan} from 'sentry/views/insights/common/queries/useHasFirstSpan';
3737
import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
38+
import {combineMeta} from 'sentry/views/insights/common/utils/combineMeta';
3839
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
3940
import {useSamplesDrawer} from 'sentry/views/insights/common/utils/useSamplesDrawer';
4041
import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
@@ -229,25 +230,6 @@ function PageWithProviders() {
229230

230231
export default PageWithProviders;
231232

232-
const combineMeta = (
233-
meta1?: EventsMetaType,
234-
meta2?: EventsMetaType
235-
): EventsMetaType | undefined => {
236-
if (!meta1 && !meta2) {
237-
return undefined;
238-
}
239-
if (!meta1) {
240-
return meta2;
241-
}
242-
if (!meta2) {
243-
return meta1;
244-
}
245-
return {
246-
fields: {...meta1.fields, ...meta2.fields},
247-
units: {...meta1.units, ...meta2.units},
248-
};
249-
};
250-
251233
// TODO - this won't be needed once we migrate to EAP
252234
const addCustomMeta = (meta?: EventsMetaType) => {
253235
if (meta?.fields) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type {EventsMetaType} from 'sentry/utils/discover/eventView';
2+
import {combineMeta} from 'sentry/views/insights/common/utils/combineMeta';
3+
4+
describe('combineMeta', () => {
5+
it('should combine meta', () => {
6+
const meta1: EventsMetaType = {
7+
fields: {a: 'boolean'},
8+
units: {a: 'boolean'},
9+
};
10+
const meta2: EventsMetaType = {
11+
fields: {b: 'duration'},
12+
units: {b: 'millisecond'},
13+
};
14+
15+
const combinedMeta = combineMeta(meta1, meta2);
16+
expect(combinedMeta).toEqual({
17+
fields: {a: 'boolean', b: 'duration'},
18+
units: {a: 'boolean', b: 'millisecond'},
19+
});
20+
});
21+
22+
it('should return undefined if both meta are undefined', () => {
23+
const combinedMeta = combineMeta(undefined, undefined);
24+
expect(combinedMeta).toBeUndefined();
25+
});
26+
27+
it('should return meta1 if meta2 is undefined', () => {
28+
const meta1: EventsMetaType = {
29+
fields: {a: 'boolean'},
30+
units: {a: 'boolean'},
31+
};
32+
const combinedMeta = combineMeta(meta1, undefined);
33+
expect(combinedMeta).toEqual(meta1);
34+
});
35+
36+
it('should combine 3 metas', () => {
37+
const meta1: EventsMetaType = {
38+
fields: {a: 'boolean'},
39+
units: {a: 'boolean'},
40+
};
41+
const meta2: EventsMetaType = {
42+
fields: {b: 'duration'},
43+
units: {b: 'millisecond'},
44+
};
45+
const meta3: EventsMetaType = {
46+
fields: {c: 'integer'},
47+
units: {},
48+
};
49+
50+
const combinedMeta = combineMeta(meta1, meta2, meta3);
51+
expect(combinedMeta).toEqual({
52+
fields: {a: 'boolean', b: 'duration', c: 'integer'},
53+
units: {a: 'boolean', b: 'millisecond'},
54+
});
55+
});
56+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type {EventsMetaType} from 'sentry/utils/discover/eventView';
2+
3+
export const combineMeta = (
4+
...metas: Array<EventsMetaType | undefined>
5+
): EventsMetaType | undefined => {
6+
const definedMetas = metas.filter(meta => meta !== undefined);
7+
8+
if (definedMetas.length === 0) {
9+
return undefined;
10+
}
11+
12+
const finalMeta: EventsMetaType = {
13+
fields: {},
14+
units: {},
15+
};
16+
17+
definedMetas.forEach(meta => {
18+
finalMeta.fields = {...finalMeta.fields, ...meta.fields};
19+
finalMeta.units = {...finalMeta.units, ...meta.units};
20+
});
21+
22+
return finalMeta;
23+
};

static/app/views/insights/llmMonitoring/components/tables/pipelinesTable.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {useNavigate} from 'sentry/utils/useNavigate';
2828
import useOrganization from 'sentry/utils/useOrganization';
2929
import {renderHeadCell} from 'sentry/views/insights/common/components/tableCells/renderHeadCell';
3030
import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover';
31+
import {combineMeta} from 'sentry/views/insights/common/utils/combineMeta';
3132
import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
3233
import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
3334
import type {SpanMetricsResponse} from 'sentry/views/insights/types';
@@ -105,7 +106,13 @@ export function PipelinesTable() {
105106
sort = {field: 'epm()', kind: 'desc'};
106107
}
107108

108-
const {data, isPending, meta, pageLinks, error} = useSpanMetrics(
109+
const {
110+
data,
111+
isPending,
112+
meta: baseMeta,
113+
pageLinks,
114+
error,
115+
} = useSpanMetrics(
109116
{
110117
search: MutableSearch.fromQueryObject({
111118
'span.category': 'ai.pipeline',
@@ -125,7 +132,11 @@ export function PipelinesTable() {
125132
'api.ai-pipelines.view'
126133
);
127134

128-
const {data: tokensUsedData, isPending: tokensUsedLoading} = useSpanMetrics(
135+
const {
136+
data: tokensUsedData,
137+
meta: tokensUsedMeta,
138+
isPending: tokensUsedLoading,
139+
} = useSpanMetrics(
129140
{
130141
search: new MutableSearch(
131142
`span.category:ai span.ai.pipeline.group:[${(data as Row[])
@@ -140,6 +151,7 @@ export function PipelinesTable() {
140151

141152
const {
142153
data: tokenCostData,
154+
meta: tokenCostMeta,
143155
isPending: tokenCostLoading,
144156
error: tokenCostError,
145157
} = useSpanMetrics(
@@ -178,6 +190,8 @@ export function PipelinesTable() {
178190
return row;
179191
});
180192

193+
const meta = combineMeta(baseMeta, tokensUsedMeta, tokenCostMeta);
194+
181195
const handleCursor: CursorHandler = (newCursor, pathname, query) => {
182196
navigate({
183197
pathname,

0 commit comments

Comments
 (0)