File tree Expand file tree Collapse file tree
apps/sim/lib/copilot/request Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ vi.mock('@opentelemetry/api', () => ({
2121} ) )
2222
2323import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
24- import { recordSimToolMetric } from '@/lib/copilot/request/metrics'
24+ import { normalizeToolAgentId , recordSimToolMetric } from '@/lib/copilot/request/metrics'
2525
2626describe ( 'recordSimToolMetric' , ( ) => {
2727 beforeEach ( ( ) => {
@@ -66,4 +66,13 @@ describe('recordSimToolMetric', () => {
6666 [ TraceAttr . GenAiAgentName ] : 'other' ,
6767 } )
6868 } )
69+
70+ it . each ( [
71+ { agentId : 'main' , expected : 'main' } ,
72+ { agentId : 'workflow' , expected : 'workflow' } ,
73+ { agentId : 'tenant-defined-agent' , expected : 'other' } ,
74+ { agentId : '' , expected : 'other' } ,
75+ ] ) ( 'normalizes $agentId to $expected for every telemetry signal' , ( { agentId, expected } ) => {
76+ expect ( normalizeToolAgentId ( agentId ) ) . toBe ( expected )
77+ } )
6978} )
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ const REGISTERED_AGENT_IDS = new Set([
7373 ...Object . values ( TOOL_CATALOG ) . flatMap ( ( { subagentId } ) => ( subagentId ? [ subagentId ] : [ ] ) ) ,
7474] )
7575
76- function cappedAgentId ( agentId : string ) : string {
76+ export function normalizeToolAgentId ( agentId : string ) : string {
7777 return REGISTERED_AGENT_IDS . has ( agentId ) ? agentId : 'other'
7878}
7979
@@ -91,7 +91,7 @@ export function recordSimToolMetric(
9191 [ TraceAttr . ToolName ] : cappedToolName ( name ) ,
9292 [ TraceAttr . ToolExecutor ] : 'sim' ,
9393 [ TraceAttr . ToolOutcome ] : outcome ,
94- [ TraceAttr . GenAiAgentName ] : cappedAgentId ( agentId ) ,
94+ [ TraceAttr . GenAiAgentName ] : normalizeToolAgentId ( agentId ) ,
9595 }
9696 toolCalls . add ( 1 , attrs )
9797 if ( durationMs >= 0 ) toolDuration . record ( durationMs , attrs )
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
2323import { TraceSpan } from '@/lib/copilot/generated/trace-spans-v1'
2424import { contextFromRequestHeaders } from '@/lib/copilot/request/go/propagation'
25+ import { normalizeToolAgentId } from '@/lib/copilot/request/metrics'
2526import { isExplicitStopReason } from '@/lib/copilot/request/session/abort-reason'
2627
2728// OTel GenAI content-capture env var (spec:
@@ -300,7 +301,7 @@ export async function withCopilotToolSpan<T>(
300301 [ TraceAttr . ToolName ] : input . toolName ,
301302 [ TraceAttr . ToolCallId ] : input . toolCallId ,
302303 [ TraceAttr . ToolExecutor ] : 'sim' ,
303- [ TraceAttr . GenAiAgentName ] : input . agentName ,
304+ [ TraceAttr . GenAiAgentName ] : normalizeToolAgentId ( input . agentName ) ,
304305 ...( input . runId ? { [ TraceAttr . RunId ] : input . runId } : { } ) ,
305306 ...( input . chatId ? { [ TraceAttr . ChatId ] : input . chatId } : { } ) ,
306307 ...( typeof input . argsBytes === 'number'
You can’t perform that action at this time.
0 commit comments