Skip to content

Commit af05c8c

Browse files
committed
feat(copilot): attribute tool latency to agents
1 parent 4302150 commit af05c8c

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

apps/sim/lib/copilot/request/metrics.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('recordSimToolMetric', () => {
2929
})
3030

3131
it.each(['main', 'workflow'])(
32-
'attributes call counts to the registered %s agent without adding it to duration',
32+
'attributes call counts and duration to the registered %s agent',
3333
(agentId) => {
3434
recordSimToolMetric('read', agentId, 'success', 125)
3535

@@ -42,7 +42,10 @@ describe('recordSimToolMetric', () => {
4242
...baseAttributes,
4343
[TraceAttr.GenAiAgentName]: agentId,
4444
})
45-
expect(toolDurationRecord).toHaveBeenCalledWith(125, baseAttributes)
45+
expect(toolDurationRecord).toHaveBeenCalledWith(125, {
46+
...baseAttributes,
47+
[TraceAttr.GenAiAgentName]: agentId,
48+
})
4649
}
4750
)
4851

@@ -58,6 +61,9 @@ describe('recordSimToolMetric', () => {
5861
...baseAttributes,
5962
[TraceAttr.GenAiAgentName]: 'other',
6063
})
61-
expect(toolDurationRecord).toHaveBeenCalledWith(125, baseAttributes)
64+
expect(toolDurationRecord).toHaveBeenCalledWith(125, {
65+
...baseAttributes,
66+
[TraceAttr.GenAiAgentName]: 'other',
67+
})
6268
})
6369
})

apps/sim/lib/copilot/request/metrics.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// contracts/metrics_v1.go) so the Go∪Sim union is queryable as one series set
66
// — e.g. `copilot.tool.duration` split by `tool.executor` (go|client|sim).
77
//
8-
// Bounded cardinality only: tool.name is capped to the shared tool catalog
9-
// (else "other"); vfs phase / file-read outcome are bounded sets. NEVER a
10-
// user/chat/request id (those explode Prometheus series).
8+
// Bounded cardinality only: tool.name and gen_ai.agent.name are capped to the
9+
// shared catalogs (else "other"); vfs phase / file-read outcome are bounded
10+
// sets. NEVER a user/chat/request id (those explode Prometheus series).
1111
import { type Counter, type Histogram, metrics } from '@opentelemetry/api'
1212
import { Metric } from '@/lib/copilot/generated/metrics-v1'
1313
import { TOOL_CATALOG } from '@/lib/copilot/generated/tool-catalog-v1'
@@ -91,11 +91,9 @@ export function recordSimToolMetric(
9191
[TraceAttr.ToolName]: cappedToolName(name),
9292
[TraceAttr.ToolExecutor]: 'sim',
9393
[TraceAttr.ToolOutcome]: outcome,
94-
}
95-
toolCalls.add(1, {
96-
...baseAttrs,
9794
[TraceAttr.GenAiAgentName]: cappedAgentId(agentId),
98-
})
95+
}
96+
toolCalls.add(1, baseAttrs)
9997
if (durationMs >= 0) toolDuration.record(durationMs, baseAttrs)
10098
}
10199

0 commit comments

Comments
 (0)