Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading