diff --git a/static/app/views/insights/pages/agents/utils/referrers.tsx b/static/app/views/insights/pages/agents/utils/referrers.tsx index ae58e8ef0591..0ee66a18aee9 100644 --- a/static/app/views/insights/pages/agents/utils/referrers.tsx +++ b/static/app/views/insights/pages/agents/utils/referrers.tsx @@ -1,4 +1,5 @@ export enum Referrer { + TRACE_DRAWER = 'api.insights.agent-monitoring.trace-drawer', TRACE_DRAWER_TOOL_USAGE = 'api.insights.agent-monitoring.trace-drawer-tool-usage', TRACES_TABLE = 'api.insights.agent-monitoring.traces-table', ONBOARDING = 'api.insights.agent-monitoring.onboarding', diff --git a/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.spec.tsx b/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.spec.tsx index 277571eb5766..7c627bbcb5d8 100644 --- a/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.spec.tsx +++ b/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.spec.tsx @@ -222,6 +222,37 @@ describe('getHighlightedSpanAttributes', () => { expect(result.find(attr => attr.name === 'Result Size')?.value).toBe('4.1 kB'); }); + it('uses the AI trace drawer referrer for the tool result size baseline', async () => { + const baselineRequest = MockApiClient.addMockResponse({ + url: '/organizations/org-slug/events/', + body: {data: [{'avg(gen_ai.tool.call.result.size)': 2000}]}, + }); + const result = getHighlightedSpanAttributes({ + spanId: '123', + projectId: 1, + attributes: { + 'gen_ai.operation.type': 'tool', + 'gen_ai.tool.name': 'search', + 'gen_ai.tool.call.result.size': 4000, + }, + }); + const size = result.find(attr => attr.name === 'Result Size'); + if (!isValidElement(size?.value)) { + throw new Error('Expected tool result size to be a React element'); + } + render(size.value); + + expect(await screen.findByText('100% larger than avg 2 kB')).toBeInTheDocument(); + expect(baselineRequest).toHaveBeenCalledWith( + '/organizations/org-slug/events/', + expect.objectContaining({ + query: expect.objectContaining({ + referrer: 'api.insights.agent-monitoring.trace-drawer', + }), + }) + ); + }); + it('should include tokens attribute when values are present', () => { const attributes = { 'gen_ai.operation.type': 'ai_client', diff --git a/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.tsx b/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.tsx index 3456f383da47..54fb0fee97fc 100644 --- a/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.tsx +++ b/static/app/views/performance/traceDetails/traceDrawer/details/highlightedAttributes.tsx @@ -157,7 +157,7 @@ function ToolResultSize({ project: [projectId], statsPeriod: '24h', query: search.formatString(), - referrer: 'api.explore.spans-aggregates-table', + referrer: Referrer.TRACE_DRAWER, }, staleTime: 60_000, }