@google/gemini-cli-core 0.10.0-nightly.20250926.1487841d → 0.10.0-nightly.20251009.cd354aeb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -71
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +46 -0
- package/dist/src/agents/codebase-investigator.js +136 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +92 -0
- package/dist/src/agents/executor.js +580 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.d.ts +6 -0
- package/dist/src/agents/executor.test.js +595 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +46 -0
- package/dist/src/agents/invocation.js +102 -0
- package/dist/src/agents/invocation.js.map +1 -0
- package/dist/src/agents/invocation.test.d.ts +6 -0
- package/dist/src/agents/invocation.test.js +215 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +36 -0
- package/dist/src/agents/registry.js +60 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/registry.test.d.ts +6 -0
- package/dist/src/agents/registry.test.js +146 -0
- package/dist/src/agents/registry.test.js.map +1 -0
- package/dist/src/agents/schema-utils.d.ts +39 -0
- package/dist/src/agents/schema-utils.js +57 -0
- package/dist/src/agents/schema-utils.js.map +1 -0
- package/dist/src/agents/schema-utils.test.d.ts +6 -0
- package/dist/src/agents/schema-utils.test.js +144 -0
- package/dist/src/agents/schema-utils.test.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +38 -0
- package/dist/src/agents/subagent-tool-wrapper.js +48 -0
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.test.d.ts +6 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js +112 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +145 -0
- package/dist/src/agents/types.js +18 -0
- package/dist/src/agents/types.js.map +1 -0
- package/dist/src/agents/utils.d.ts +15 -0
- package/dist/src/agents/utils.js +29 -0
- package/dist/src/agents/utils.js.map +1 -0
- package/dist/src/agents/utils.test.d.ts +6 -0
- package/dist/src/agents/utils.test.js +87 -0
- package/dist/src/agents/utils.test.js.map +1 -0
- package/dist/src/code_assist/setup.js +4 -2
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/config/config.d.ts +28 -5
- package/dist/src/config/config.js +61 -7
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +63 -0
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/baseLlmClient.js +19 -21
- package/dist/src/core/baseLlmClient.js.map +1 -1
- package/dist/src/core/baseLlmClient.test.js +57 -17
- package/dist/src/core/baseLlmClient.test.js.map +1 -1
- package/dist/src/core/client.d.ts +2 -0
- package/dist/src/core/client.js +52 -43
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +300 -95
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +3 -1
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +33 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +6 -0
- package/dist/src/core/geminiChat.js +21 -18
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +20 -19
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +11 -11
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.d.ts +2 -1
- package/dist/src/core/prompts.js +88 -15
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +73 -24
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/turn.d.ts +10 -2
- package/dist/src/core/turn.js +6 -1
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +1 -1
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/ide/detect-ide.d.ts +1 -0
- package/dist/src/ide/detect-ide.js +4 -1
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +11 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.js +3 -3
- package/dist/src/ide/ide-client.test.js +4 -4
- package/dist/src/ide/ide-installer.js +1 -1
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +13 -1
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +2 -1
- package/dist/src/services/chatRecordingService.js +2 -1
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +11 -0
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +2 -0
- package/dist/src/services/shellExecutionService.js +48 -7
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +13 -4
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +12 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +79 -9
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +99 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +11 -3
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +27 -4
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +6 -24
- package/dist/src/telemetry/constants.js +7 -25
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +5 -3
- package/dist/src/telemetry/index.js +10 -3
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +6 -1
- package/dist/src/telemetry/loggers.js +132 -12
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -3
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +160 -13
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/memory-monitor.d.ts +149 -0
- package/dist/src/telemetry/memory-monitor.js +335 -0
- package/dist/src/telemetry/memory-monitor.js.map +1 -0
- package/dist/src/telemetry/memory-monitor.test.d.ts +6 -0
- package/dist/src/telemetry/memory-monitor.test.js +472 -0
- package/dist/src/telemetry/memory-monitor.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +392 -20
- package/dist/src/telemetry/metrics.js +463 -235
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +391 -55
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +37 -1
- package/dist/src/telemetry/types.js +60 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +2 -2
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/mock-tool.d.ts +28 -3
- package/dist/src/test-utils/mock-tool.js +71 -1
- package/dist/src/test-utils/mock-tool.js.map +1 -1
- package/dist/src/tools/glob.js +2 -1
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +3 -2
- package/dist/src/tools/mcp-client.js +44 -30
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +168 -5
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/shell.js +2 -2
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +1 -1
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +20 -1
- package/dist/src/tools/smart-edit.js +149 -9
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +150 -29
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +8 -0
- package/dist/src/tools/tool-names.js +17 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.test.js +10 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/web-fetch.js +3 -0
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +44 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/write-file.js +2 -1
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +1 -1
- package/dist/src/tools/write-todos.js +4 -3
- package/dist/src/tools/write-todos.js.map +1 -1
- package/dist/src/utils/editCorrector.js +2 -2
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +1 -0
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +1 -0
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -1
- package/dist/src/utils/errorParsing.js +5 -33
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +0 -88
- package/dist/src/utils/errorParsing.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.js +26 -45
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- package/dist/src/utils/formatters.d.ts +1 -0
- package/dist/src/utils/formatters.js +2 -1
- package/dist/src/utils/formatters.js.map +1 -1
- package/dist/src/utils/formatters.test.d.ts +6 -0
- package/dist/src/utils/formatters.test.js +26 -0
- package/dist/src/utils/formatters.test.js.map +1 -0
- package/dist/src/utils/googleErrors.d.ts +104 -0
- package/dist/src/utils/googleErrors.js +108 -0
- package/dist/src/utils/googleErrors.js.map +1 -0
- package/dist/src/utils/googleErrors.test.d.ts +6 -0
- package/dist/src/utils/googleErrors.test.js +212 -0
- package/dist/src/utils/googleErrors.test.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.d.ts +35 -0
- package/dist/src/utils/googleQuotaErrors.js +108 -0
- package/dist/src/utils/googleQuotaErrors.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.test.d.ts +6 -0
- package/dist/src/utils/googleQuotaErrors.test.js +189 -0
- package/dist/src/utils/googleQuotaErrors.test.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.js +13 -4
- package/dist/src/utils/llm-edit-fixer.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.test.js +81 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +1 -0
- package/dist/src/utils/memoryDiscovery.js +2 -1
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +99 -21
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +13 -20
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +14 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.d.ts +0 -2
- package/dist/src/utils/quotaErrorDetection.js +0 -46
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.d.ts +3 -1
- package/dist/src/utils/retry.js +53 -161
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +87 -146
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/terminalSerializer.d.ts +1 -4
- package/dist/src/utils/terminalSerializer.js +3 -3
- package/dist/src/utils/terminalSerializer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/test-utils/tools.d.ts +0 -45
- package/dist/src/test-utils/tools.js +0 -105
- package/dist/src/test-utils/tools.js.map +0 -1
|
@@ -4,9 +4,250 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { diag, metrics, ValueType } from '@opentelemetry/api';
|
|
7
|
-
import { SERVICE_NAME,
|
|
7
|
+
import { SERVICE_NAME, EVENT_CHAT_COMPRESSION } from './constants.js';
|
|
8
|
+
import { AuthType } from '../core/contentGenerator.js';
|
|
9
|
+
const TOOL_CALL_COUNT = 'gemini_cli.tool.call.count';
|
|
10
|
+
const TOOL_CALL_LATENCY = 'gemini_cli.tool.call.latency';
|
|
11
|
+
const API_REQUEST_COUNT = 'gemini_cli.api.request.count';
|
|
12
|
+
const API_REQUEST_LATENCY = 'gemini_cli.api.request.latency';
|
|
13
|
+
const TOKEN_USAGE = 'gemini_cli.token.usage';
|
|
14
|
+
const SESSION_COUNT = 'gemini_cli.session.count';
|
|
15
|
+
const FILE_OPERATION_COUNT = 'gemini_cli.file.operation.count';
|
|
16
|
+
const INVALID_CHUNK_COUNT = 'gemini_cli.chat.invalid_chunk.count';
|
|
17
|
+
const CONTENT_RETRY_COUNT = 'gemini_cli.chat.content_retry.count';
|
|
18
|
+
const CONTENT_RETRY_FAILURE_COUNT = 'gemini_cli.chat.content_retry_failure.count';
|
|
19
|
+
const MODEL_ROUTING_LATENCY = 'gemini_cli.model_routing.latency';
|
|
20
|
+
const MODEL_ROUTING_FAILURE_COUNT = 'gemini_cli.model_routing.failure.count';
|
|
21
|
+
const MODEL_SLASH_COMMAND_CALL_COUNT = 'gemini_cli.slash_command.model.call_count';
|
|
22
|
+
// Agent Metrics
|
|
23
|
+
const AGENT_RUN_COUNT = 'gemini_cli.agent.run.count';
|
|
24
|
+
const AGENT_DURATION_MS = 'gemini_cli.agent.duration';
|
|
25
|
+
const AGENT_TURNS = 'gemini_cli.agent.turns';
|
|
26
|
+
// OpenTelemetry GenAI Semantic Convention Metrics
|
|
27
|
+
const GEN_AI_CLIENT_TOKEN_USAGE = 'gen_ai.client.token.usage';
|
|
28
|
+
const GEN_AI_CLIENT_OPERATION_DURATION = 'gen_ai.client.operation.duration';
|
|
8
29
|
// Performance Monitoring Metrics
|
|
9
|
-
|
|
30
|
+
const STARTUP_TIME = 'gemini_cli.startup.duration';
|
|
31
|
+
const MEMORY_USAGE = 'gemini_cli.memory.usage';
|
|
32
|
+
const CPU_USAGE = 'gemini_cli.cpu.usage';
|
|
33
|
+
const TOOL_QUEUE_DEPTH = 'gemini_cli.tool.queue.depth';
|
|
34
|
+
const TOOL_EXECUTION_BREAKDOWN = 'gemini_cli.tool.execution.breakdown';
|
|
35
|
+
const TOKEN_EFFICIENCY = 'gemini_cli.token.efficiency';
|
|
36
|
+
const API_REQUEST_BREAKDOWN = 'gemini_cli.api.request.breakdown';
|
|
37
|
+
const PERFORMANCE_SCORE = 'gemini_cli.performance.score';
|
|
38
|
+
const REGRESSION_DETECTION = 'gemini_cli.performance.regression';
|
|
39
|
+
const REGRESSION_PERCENTAGE_CHANGE = 'gemini_cli.performance.regression.percentage_change';
|
|
40
|
+
const BASELINE_COMPARISON = 'gemini_cli.performance.baseline.comparison';
|
|
41
|
+
const baseMetricDefinition = {
|
|
42
|
+
getCommonAttributes: (config) => ({
|
|
43
|
+
'session.id': config.getSessionId(),
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
const COUNTER_DEFINITIONS = {
|
|
47
|
+
[TOOL_CALL_COUNT]: {
|
|
48
|
+
description: 'Counts tool calls, tagged by function name and success.',
|
|
49
|
+
valueType: ValueType.INT,
|
|
50
|
+
assign: (c) => (toolCallCounter = c),
|
|
51
|
+
attributes: {},
|
|
52
|
+
},
|
|
53
|
+
[API_REQUEST_COUNT]: {
|
|
54
|
+
description: 'Counts API requests, tagged by model and status.',
|
|
55
|
+
valueType: ValueType.INT,
|
|
56
|
+
assign: (c) => (apiRequestCounter = c),
|
|
57
|
+
attributes: {},
|
|
58
|
+
},
|
|
59
|
+
[TOKEN_USAGE]: {
|
|
60
|
+
description: 'Counts the total number of tokens used.',
|
|
61
|
+
valueType: ValueType.INT,
|
|
62
|
+
assign: (c) => (tokenUsageCounter = c),
|
|
63
|
+
attributes: {},
|
|
64
|
+
},
|
|
65
|
+
[SESSION_COUNT]: {
|
|
66
|
+
description: 'Count of CLI sessions started.',
|
|
67
|
+
valueType: ValueType.INT,
|
|
68
|
+
assign: (c) => (sessionCounter = c),
|
|
69
|
+
attributes: {},
|
|
70
|
+
},
|
|
71
|
+
[FILE_OPERATION_COUNT]: {
|
|
72
|
+
description: 'Counts file operations (create, read, update).',
|
|
73
|
+
valueType: ValueType.INT,
|
|
74
|
+
assign: (c) => (fileOperationCounter = c),
|
|
75
|
+
attributes: {},
|
|
76
|
+
},
|
|
77
|
+
[INVALID_CHUNK_COUNT]: {
|
|
78
|
+
description: 'Counts invalid chunks received from a stream.',
|
|
79
|
+
valueType: ValueType.INT,
|
|
80
|
+
assign: (c) => (invalidChunkCounter = c),
|
|
81
|
+
attributes: {},
|
|
82
|
+
},
|
|
83
|
+
[CONTENT_RETRY_COUNT]: {
|
|
84
|
+
description: 'Counts retries due to content errors (e.g., empty stream).',
|
|
85
|
+
valueType: ValueType.INT,
|
|
86
|
+
assign: (c) => (contentRetryCounter = c),
|
|
87
|
+
attributes: {},
|
|
88
|
+
},
|
|
89
|
+
[CONTENT_RETRY_FAILURE_COUNT]: {
|
|
90
|
+
description: 'Counts occurrences of all content retries failing.',
|
|
91
|
+
valueType: ValueType.INT,
|
|
92
|
+
assign: (c) => (contentRetryFailureCounter = c),
|
|
93
|
+
attributes: {},
|
|
94
|
+
},
|
|
95
|
+
[MODEL_ROUTING_FAILURE_COUNT]: {
|
|
96
|
+
description: 'Counts model routing failures.',
|
|
97
|
+
valueType: ValueType.INT,
|
|
98
|
+
assign: (c) => (modelRoutingFailureCounter = c),
|
|
99
|
+
attributes: {},
|
|
100
|
+
},
|
|
101
|
+
[MODEL_SLASH_COMMAND_CALL_COUNT]: {
|
|
102
|
+
description: 'Counts model slash command calls.',
|
|
103
|
+
valueType: ValueType.INT,
|
|
104
|
+
assign: (c) => (modelSlashCommandCallCounter = c),
|
|
105
|
+
attributes: {},
|
|
106
|
+
},
|
|
107
|
+
[EVENT_CHAT_COMPRESSION]: {
|
|
108
|
+
description: 'Counts chat compression events.',
|
|
109
|
+
valueType: ValueType.INT,
|
|
110
|
+
assign: (c) => (chatCompressionCounter = c),
|
|
111
|
+
attributes: {},
|
|
112
|
+
},
|
|
113
|
+
[AGENT_RUN_COUNT]: {
|
|
114
|
+
description: 'Counts agent runs, tagged by name and termination reason.',
|
|
115
|
+
valueType: ValueType.INT,
|
|
116
|
+
assign: (c) => (agentRunCounter = c),
|
|
117
|
+
attributes: {},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
const HISTOGRAM_DEFINITIONS = {
|
|
121
|
+
[TOOL_CALL_LATENCY]: {
|
|
122
|
+
description: 'Latency of tool calls in milliseconds.',
|
|
123
|
+
unit: 'ms',
|
|
124
|
+
valueType: ValueType.INT,
|
|
125
|
+
assign: (h) => (toolCallLatencyHistogram = h),
|
|
126
|
+
attributes: {},
|
|
127
|
+
},
|
|
128
|
+
[API_REQUEST_LATENCY]: {
|
|
129
|
+
description: 'Latency of API requests in milliseconds.',
|
|
130
|
+
unit: 'ms',
|
|
131
|
+
valueType: ValueType.INT,
|
|
132
|
+
assign: (h) => (apiRequestLatencyHistogram = h),
|
|
133
|
+
attributes: {},
|
|
134
|
+
},
|
|
135
|
+
[MODEL_ROUTING_LATENCY]: {
|
|
136
|
+
description: 'Latency of model routing decisions in milliseconds.',
|
|
137
|
+
unit: 'ms',
|
|
138
|
+
valueType: ValueType.INT,
|
|
139
|
+
assign: (h) => (modelRoutingLatencyHistogram = h),
|
|
140
|
+
attributes: {},
|
|
141
|
+
},
|
|
142
|
+
[AGENT_DURATION_MS]: {
|
|
143
|
+
description: 'Duration of agent runs in milliseconds.',
|
|
144
|
+
unit: 'ms',
|
|
145
|
+
valueType: ValueType.INT,
|
|
146
|
+
assign: (h) => (agentDurationHistogram = h),
|
|
147
|
+
attributes: {},
|
|
148
|
+
},
|
|
149
|
+
[AGENT_TURNS]: {
|
|
150
|
+
description: 'Number of turns taken by agents.',
|
|
151
|
+
unit: 'turns',
|
|
152
|
+
valueType: ValueType.INT,
|
|
153
|
+
assign: (h) => (agentTurnsHistogram = h),
|
|
154
|
+
attributes: {},
|
|
155
|
+
},
|
|
156
|
+
[GEN_AI_CLIENT_TOKEN_USAGE]: {
|
|
157
|
+
description: 'Number of input and output tokens used.',
|
|
158
|
+
unit: 'token',
|
|
159
|
+
valueType: ValueType.INT,
|
|
160
|
+
assign: (h) => (genAiClientTokenUsageHistogram = h),
|
|
161
|
+
attributes: {},
|
|
162
|
+
},
|
|
163
|
+
[GEN_AI_CLIENT_OPERATION_DURATION]: {
|
|
164
|
+
description: 'GenAI operation duration.',
|
|
165
|
+
unit: 's',
|
|
166
|
+
valueType: ValueType.DOUBLE,
|
|
167
|
+
assign: (h) => (genAiClientOperationDurationHistogram = h),
|
|
168
|
+
attributes: {},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
const PERFORMANCE_COUNTER_DEFINITIONS = {
|
|
172
|
+
[REGRESSION_DETECTION]: {
|
|
173
|
+
description: 'Performance regression detection events.',
|
|
174
|
+
valueType: ValueType.INT,
|
|
175
|
+
assign: (c) => (regressionDetectionCounter = c),
|
|
176
|
+
attributes: {},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const PERFORMANCE_HISTOGRAM_DEFINITIONS = {
|
|
180
|
+
[STARTUP_TIME]: {
|
|
181
|
+
description: 'CLI startup time in milliseconds, broken down by initialization phase.',
|
|
182
|
+
unit: 'ms',
|
|
183
|
+
valueType: ValueType.DOUBLE,
|
|
184
|
+
assign: (h) => (startupTimeHistogram = h),
|
|
185
|
+
attributes: {},
|
|
186
|
+
},
|
|
187
|
+
[MEMORY_USAGE]: {
|
|
188
|
+
description: 'Memory usage in bytes.',
|
|
189
|
+
unit: 'bytes',
|
|
190
|
+
valueType: ValueType.INT,
|
|
191
|
+
assign: (h) => (memoryUsageGauge = h),
|
|
192
|
+
attributes: {},
|
|
193
|
+
},
|
|
194
|
+
[CPU_USAGE]: {
|
|
195
|
+
description: 'CPU usage percentage.',
|
|
196
|
+
unit: 'percent',
|
|
197
|
+
valueType: ValueType.DOUBLE,
|
|
198
|
+
assign: (h) => (cpuUsageGauge = h),
|
|
199
|
+
attributes: {},
|
|
200
|
+
},
|
|
201
|
+
[TOOL_QUEUE_DEPTH]: {
|
|
202
|
+
description: 'Number of tools in execution queue.',
|
|
203
|
+
unit: 'count',
|
|
204
|
+
valueType: ValueType.INT,
|
|
205
|
+
assign: (h) => (toolQueueDepthGauge = h),
|
|
206
|
+
attributes: {},
|
|
207
|
+
},
|
|
208
|
+
[TOOL_EXECUTION_BREAKDOWN]: {
|
|
209
|
+
description: 'Tool execution time breakdown by phase in milliseconds.',
|
|
210
|
+
unit: 'ms',
|
|
211
|
+
valueType: ValueType.INT,
|
|
212
|
+
assign: (h) => (toolExecutionBreakdownHistogram = h),
|
|
213
|
+
attributes: {},
|
|
214
|
+
},
|
|
215
|
+
[TOKEN_EFFICIENCY]: {
|
|
216
|
+
description: 'Token efficiency metrics (tokens per operation, cache hit rate, etc.).',
|
|
217
|
+
unit: 'ratio',
|
|
218
|
+
valueType: ValueType.DOUBLE,
|
|
219
|
+
assign: (h) => (tokenEfficiencyHistogram = h),
|
|
220
|
+
attributes: {},
|
|
221
|
+
},
|
|
222
|
+
[API_REQUEST_BREAKDOWN]: {
|
|
223
|
+
description: 'API request time breakdown by phase in milliseconds.',
|
|
224
|
+
unit: 'ms',
|
|
225
|
+
valueType: ValueType.INT,
|
|
226
|
+
assign: (h) => (apiRequestBreakdownHistogram = h),
|
|
227
|
+
attributes: {},
|
|
228
|
+
},
|
|
229
|
+
[PERFORMANCE_SCORE]: {
|
|
230
|
+
description: 'Composite performance score (0-100).',
|
|
231
|
+
unit: 'score',
|
|
232
|
+
valueType: ValueType.DOUBLE,
|
|
233
|
+
assign: (h) => (performanceScoreGauge = h),
|
|
234
|
+
attributes: {},
|
|
235
|
+
},
|
|
236
|
+
[REGRESSION_PERCENTAGE_CHANGE]: {
|
|
237
|
+
description: 'Percentage change compared to baseline for detected regressions.',
|
|
238
|
+
unit: 'percent',
|
|
239
|
+
valueType: ValueType.DOUBLE,
|
|
240
|
+
assign: (h) => (regressionPercentageChangeHistogram = h),
|
|
241
|
+
attributes: {},
|
|
242
|
+
},
|
|
243
|
+
[BASELINE_COMPARISON]: {
|
|
244
|
+
description: 'Performance comparison to established baseline (percentage change).',
|
|
245
|
+
unit: 'percent',
|
|
246
|
+
valueType: ValueType.DOUBLE,
|
|
247
|
+
assign: (h) => (baselineComparisonHistogram = h),
|
|
248
|
+
attributes: {},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
10
251
|
export var FileOperation;
|
|
11
252
|
(function (FileOperation) {
|
|
12
253
|
FileOperation["CREATE"] = "create";
|
|
@@ -43,12 +284,27 @@ export var ApiRequestPhase;
|
|
|
43
284
|
ApiRequestPhase["RESPONSE_PROCESSING"] = "response_processing";
|
|
44
285
|
ApiRequestPhase["TOKEN_PROCESSING"] = "token_processing";
|
|
45
286
|
})(ApiRequestPhase || (ApiRequestPhase = {}));
|
|
287
|
+
export var GenAiOperationName;
|
|
288
|
+
(function (GenAiOperationName) {
|
|
289
|
+
GenAiOperationName["GENERATE_CONTENT"] = "generate_content";
|
|
290
|
+
})(GenAiOperationName || (GenAiOperationName = {}));
|
|
291
|
+
export var GenAiProviderName;
|
|
292
|
+
(function (GenAiProviderName) {
|
|
293
|
+
GenAiProviderName["GCP_GEN_AI"] = "gcp.gen_ai";
|
|
294
|
+
GenAiProviderName["GCP_VERTEX_AI"] = "gcp.vertex_ai";
|
|
295
|
+
})(GenAiProviderName || (GenAiProviderName = {}));
|
|
296
|
+
export var GenAiTokenType;
|
|
297
|
+
(function (GenAiTokenType) {
|
|
298
|
+
GenAiTokenType["INPUT"] = "input";
|
|
299
|
+
GenAiTokenType["OUTPUT"] = "output";
|
|
300
|
+
})(GenAiTokenType || (GenAiTokenType = {}));
|
|
46
301
|
let cliMeter;
|
|
47
302
|
let toolCallCounter;
|
|
48
303
|
let toolCallLatencyHistogram;
|
|
49
304
|
let apiRequestCounter;
|
|
50
305
|
let apiRequestLatencyHistogram;
|
|
51
306
|
let tokenUsageCounter;
|
|
307
|
+
let sessionCounter;
|
|
52
308
|
let fileOperationCounter;
|
|
53
309
|
let chatCompressionCounter;
|
|
54
310
|
let invalidChunkCounter;
|
|
@@ -57,6 +313,12 @@ let contentRetryFailureCounter;
|
|
|
57
313
|
let modelRoutingLatencyHistogram;
|
|
58
314
|
let modelRoutingFailureCounter;
|
|
59
315
|
let modelSlashCommandCallCounter;
|
|
316
|
+
let agentRunCounter;
|
|
317
|
+
let agentDurationHistogram;
|
|
318
|
+
let agentTurnsHistogram;
|
|
319
|
+
// OpenTelemetry GenAI Semantic Convention Metrics
|
|
320
|
+
let genAiClientTokenUsageHistogram;
|
|
321
|
+
let genAiClientOperationDurationHistogram;
|
|
60
322
|
// Performance Monitoring Metrics
|
|
61
323
|
let startupTimeHistogram;
|
|
62
324
|
let memoryUsageGauge; // Using Histogram until ObservableGauge is available
|
|
@@ -71,11 +333,6 @@ let regressionPercentageChangeHistogram;
|
|
|
71
333
|
let baselineComparisonHistogram;
|
|
72
334
|
let isMetricsInitialized = false;
|
|
73
335
|
let isPerformanceMonitoringEnabled = false;
|
|
74
|
-
function getCommonAttributes(config) {
|
|
75
|
-
return {
|
|
76
|
-
'session.id': config.getSessionId(),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
336
|
export function getMeter() {
|
|
80
337
|
if (!cliMeter) {
|
|
81
338
|
cliMeter = metrics.getMeter(SERVICE_NAME);
|
|
@@ -89,154 +346,87 @@ export function initializeMetrics(config) {
|
|
|
89
346
|
if (!meter)
|
|
90
347
|
return;
|
|
91
348
|
// Initialize core metrics
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
valueType: ValueType.INT,
|
|
95
|
-
});
|
|
96
|
-
toolCallLatencyHistogram = meter.createHistogram(METRIC_TOOL_CALL_LATENCY, {
|
|
97
|
-
description: 'Latency of tool calls in milliseconds.',
|
|
98
|
-
unit: 'ms',
|
|
99
|
-
valueType: ValueType.INT,
|
|
100
|
-
});
|
|
101
|
-
apiRequestCounter = meter.createCounter(METRIC_API_REQUEST_COUNT, {
|
|
102
|
-
description: 'Counts API requests, tagged by model and status.',
|
|
103
|
-
valueType: ValueType.INT,
|
|
104
|
-
});
|
|
105
|
-
apiRequestLatencyHistogram = meter.createHistogram(METRIC_API_REQUEST_LATENCY, {
|
|
106
|
-
description: 'Latency of API requests in milliseconds.',
|
|
107
|
-
unit: 'ms',
|
|
108
|
-
valueType: ValueType.INT,
|
|
109
|
-
});
|
|
110
|
-
tokenUsageCounter = meter.createCounter(METRIC_TOKEN_USAGE, {
|
|
111
|
-
description: 'Counts the total number of tokens used.',
|
|
112
|
-
valueType: ValueType.INT,
|
|
113
|
-
});
|
|
114
|
-
fileOperationCounter = meter.createCounter(METRIC_FILE_OPERATION_COUNT, {
|
|
115
|
-
description: 'Counts file operations (create, read, update).',
|
|
116
|
-
valueType: ValueType.INT,
|
|
117
|
-
});
|
|
118
|
-
chatCompressionCounter = meter.createCounter(EVENT_CHAT_COMPRESSION, {
|
|
119
|
-
description: 'Counts chat compression events.',
|
|
120
|
-
valueType: ValueType.INT,
|
|
121
|
-
});
|
|
122
|
-
// New counters for content errors
|
|
123
|
-
invalidChunkCounter = meter.createCounter(METRIC_INVALID_CHUNK_COUNT, {
|
|
124
|
-
description: 'Counts invalid chunks received from a stream.',
|
|
125
|
-
valueType: ValueType.INT,
|
|
126
|
-
});
|
|
127
|
-
contentRetryCounter = meter.createCounter(METRIC_CONTENT_RETRY_COUNT, {
|
|
128
|
-
description: 'Counts retries due to content errors (e.g., empty stream).',
|
|
129
|
-
valueType: ValueType.INT,
|
|
130
|
-
});
|
|
131
|
-
contentRetryFailureCounter = meter.createCounter(METRIC_CONTENT_RETRY_FAILURE_COUNT, {
|
|
132
|
-
description: 'Counts occurrences of all content retries failing.',
|
|
133
|
-
valueType: ValueType.INT,
|
|
134
|
-
});
|
|
135
|
-
modelRoutingLatencyHistogram = meter.createHistogram(METRIC_MODEL_ROUTING_LATENCY, {
|
|
136
|
-
description: 'Latency of model routing decisions in milliseconds.',
|
|
137
|
-
unit: 'ms',
|
|
138
|
-
valueType: ValueType.INT,
|
|
349
|
+
Object.entries(COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
350
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
139
351
|
});
|
|
140
|
-
|
|
141
|
-
description
|
|
142
|
-
valueType: ValueType.INT,
|
|
352
|
+
Object.entries(HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
353
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
143
354
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
valueType: ValueType.INT,
|
|
147
|
-
});
|
|
148
|
-
const sessionCounter = meter.createCounter(METRIC_SESSION_COUNT, {
|
|
149
|
-
description: 'Count of CLI sessions started.',
|
|
150
|
-
valueType: ValueType.INT,
|
|
151
|
-
});
|
|
152
|
-
sessionCounter.add(1, getCommonAttributes(config));
|
|
355
|
+
// Increment session counter after all metrics are initialized
|
|
356
|
+
sessionCounter?.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
153
357
|
// Initialize performance monitoring metrics if enabled
|
|
154
358
|
initializePerformanceMonitoring(config);
|
|
155
359
|
isMetricsInitialized = true;
|
|
156
360
|
}
|
|
157
|
-
export function recordChatCompressionMetrics(config,
|
|
361
|
+
export function recordChatCompressionMetrics(config, attributes) {
|
|
158
362
|
if (!chatCompressionCounter || !isMetricsInitialized)
|
|
159
363
|
return;
|
|
160
364
|
chatCompressionCounter.add(1, {
|
|
161
|
-
...getCommonAttributes(config),
|
|
162
|
-
...
|
|
365
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
366
|
+
...attributes,
|
|
163
367
|
});
|
|
164
368
|
}
|
|
165
|
-
export function recordToolCallMetrics(config,
|
|
369
|
+
export function recordToolCallMetrics(config, durationMs, attributes) {
|
|
166
370
|
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
|
|
167
371
|
return;
|
|
168
372
|
const metricAttributes = {
|
|
169
|
-
...getCommonAttributes(config),
|
|
170
|
-
|
|
171
|
-
success,
|
|
172
|
-
decision,
|
|
173
|
-
tool_type,
|
|
373
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
374
|
+
...attributes,
|
|
174
375
|
};
|
|
175
376
|
toolCallCounter.add(1, metricAttributes);
|
|
176
377
|
toolCallLatencyHistogram.record(durationMs, {
|
|
177
|
-
...getCommonAttributes(config),
|
|
178
|
-
function_name:
|
|
378
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
379
|
+
function_name: attributes.function_name,
|
|
179
380
|
});
|
|
180
381
|
}
|
|
181
|
-
export function
|
|
382
|
+
export function recordCustomTokenUsageMetrics(config, tokenCount, attributes) {
|
|
182
383
|
if (!tokenUsageCounter || !isMetricsInitialized)
|
|
183
384
|
return;
|
|
184
385
|
tokenUsageCounter.add(tokenCount, {
|
|
185
|
-
...getCommonAttributes(config),
|
|
186
|
-
|
|
187
|
-
type,
|
|
386
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
387
|
+
...attributes,
|
|
188
388
|
});
|
|
189
389
|
}
|
|
190
|
-
export function
|
|
390
|
+
export function recordCustomApiResponseMetrics(config, durationMs, attributes) {
|
|
191
391
|
if (!apiRequestCounter ||
|
|
192
392
|
!apiRequestLatencyHistogram ||
|
|
193
393
|
!isMetricsInitialized)
|
|
194
394
|
return;
|
|
195
395
|
const metricAttributes = {
|
|
196
|
-
...getCommonAttributes(config),
|
|
197
|
-
model,
|
|
198
|
-
status_code:
|
|
396
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
397
|
+
model: attributes.model,
|
|
398
|
+
status_code: attributes.status_code ?? 'ok',
|
|
199
399
|
};
|
|
200
400
|
apiRequestCounter.add(1, metricAttributes);
|
|
201
401
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
202
|
-
...getCommonAttributes(config),
|
|
203
|
-
model,
|
|
402
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
403
|
+
model: attributes.model,
|
|
204
404
|
});
|
|
205
405
|
}
|
|
206
|
-
export function recordApiErrorMetrics(config,
|
|
406
|
+
export function recordApiErrorMetrics(config, durationMs, attributes) {
|
|
207
407
|
if (!apiRequestCounter ||
|
|
208
408
|
!apiRequestLatencyHistogram ||
|
|
209
409
|
!isMetricsInitialized)
|
|
210
410
|
return;
|
|
211
411
|
const metricAttributes = {
|
|
212
|
-
...getCommonAttributes(config),
|
|
213
|
-
model,
|
|
214
|
-
status_code:
|
|
215
|
-
error_type:
|
|
412
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
413
|
+
model: attributes.model,
|
|
414
|
+
status_code: attributes.status_code ?? 'error',
|
|
415
|
+
error_type: attributes.error_type ?? 'unknown',
|
|
216
416
|
};
|
|
217
417
|
apiRequestCounter.add(1, metricAttributes);
|
|
218
418
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
219
|
-
...getCommonAttributes(config),
|
|
220
|
-
model,
|
|
419
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
420
|
+
model: attributes.model,
|
|
221
421
|
});
|
|
222
422
|
}
|
|
223
|
-
export function recordFileOperationMetric(config,
|
|
423
|
+
export function recordFileOperationMetric(config, attributes) {
|
|
224
424
|
if (!fileOperationCounter || !isMetricsInitialized)
|
|
225
425
|
return;
|
|
226
|
-
|
|
227
|
-
...getCommonAttributes(config),
|
|
228
|
-
|
|
229
|
-
};
|
|
230
|
-
if (lines !== undefined)
|
|
231
|
-
attributes['lines'] = lines;
|
|
232
|
-
if (mimetype !== undefined)
|
|
233
|
-
attributes['mimetype'] = mimetype;
|
|
234
|
-
if (extension !== undefined)
|
|
235
|
-
attributes['extension'] = extension;
|
|
236
|
-
if (programming_language !== undefined) {
|
|
237
|
-
attributes['programming_language'] = programming_language;
|
|
238
|
-
}
|
|
239
|
-
fileOperationCounter.add(1, attributes);
|
|
426
|
+
fileOperationCounter.add(1, {
|
|
427
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
428
|
+
...attributes,
|
|
429
|
+
});
|
|
240
430
|
}
|
|
241
431
|
// --- New Metric Recording Functions ---
|
|
242
432
|
/**
|
|
@@ -245,7 +435,7 @@ export function recordFileOperationMetric(config, operation, lines, mimetype, ex
|
|
|
245
435
|
export function recordInvalidChunk(config) {
|
|
246
436
|
if (!invalidChunkCounter || !isMetricsInitialized)
|
|
247
437
|
return;
|
|
248
|
-
invalidChunkCounter.add(1, getCommonAttributes(config));
|
|
438
|
+
invalidChunkCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
249
439
|
}
|
|
250
440
|
/**
|
|
251
441
|
* Records a metric for when a retry is triggered due to a content error.
|
|
@@ -253,7 +443,7 @@ export function recordInvalidChunk(config) {
|
|
|
253
443
|
export function recordContentRetry(config) {
|
|
254
444
|
if (!contentRetryCounter || !isMetricsInitialized)
|
|
255
445
|
return;
|
|
256
|
-
contentRetryCounter.add(1, getCommonAttributes(config));
|
|
446
|
+
contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
257
447
|
}
|
|
258
448
|
/**
|
|
259
449
|
* Records a metric for when all content error retries have failed for a request.
|
|
@@ -261,13 +451,13 @@ export function recordContentRetry(config) {
|
|
|
261
451
|
export function recordContentRetryFailure(config) {
|
|
262
452
|
if (!contentRetryFailureCounter || !isMetricsInitialized)
|
|
263
453
|
return;
|
|
264
|
-
contentRetryFailureCounter.add(1, getCommonAttributes(config));
|
|
454
|
+
contentRetryFailureCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
265
455
|
}
|
|
266
456
|
export function recordModelSlashCommand(config, event) {
|
|
267
457
|
if (!modelSlashCommandCallCounter || !isMetricsInitialized)
|
|
268
458
|
return;
|
|
269
459
|
modelSlashCommandCallCounter.add(1, {
|
|
270
|
-
...getCommonAttributes(config),
|
|
460
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
271
461
|
'slash_command.model.model_name': event.model_name,
|
|
272
462
|
});
|
|
273
463
|
}
|
|
@@ -277,18 +467,85 @@ export function recordModelRoutingMetrics(config, event) {
|
|
|
277
467
|
!isMetricsInitialized)
|
|
278
468
|
return;
|
|
279
469
|
modelRoutingLatencyHistogram.record(event.routing_latency_ms, {
|
|
280
|
-
...getCommonAttributes(config),
|
|
470
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
281
471
|
'routing.decision_model': event.decision_model,
|
|
282
472
|
'routing.decision_source': event.decision_source,
|
|
283
473
|
});
|
|
284
474
|
if (event.failed) {
|
|
285
475
|
modelRoutingFailureCounter.add(1, {
|
|
286
|
-
...getCommonAttributes(config),
|
|
476
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
287
477
|
'routing.decision_source': event.decision_source,
|
|
288
478
|
'routing.error_message': event.error_message,
|
|
289
479
|
});
|
|
290
480
|
}
|
|
291
481
|
}
|
|
482
|
+
export function recordAgentRunMetrics(config, event) {
|
|
483
|
+
if (!agentRunCounter ||
|
|
484
|
+
!agentDurationHistogram ||
|
|
485
|
+
!agentTurnsHistogram ||
|
|
486
|
+
!isMetricsInitialized)
|
|
487
|
+
return;
|
|
488
|
+
const commonAttributes = baseMetricDefinition.getCommonAttributes(config);
|
|
489
|
+
agentRunCounter.add(1, {
|
|
490
|
+
...commonAttributes,
|
|
491
|
+
agent_name: event.agent_name,
|
|
492
|
+
terminate_reason: event.terminate_reason,
|
|
493
|
+
});
|
|
494
|
+
agentDurationHistogram.record(event.duration_ms, {
|
|
495
|
+
...commonAttributes,
|
|
496
|
+
agent_name: event.agent_name,
|
|
497
|
+
});
|
|
498
|
+
agentTurnsHistogram.record(event.turn_count, {
|
|
499
|
+
...commonAttributes,
|
|
500
|
+
agent_name: event.agent_name,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
// OpenTelemetry GenAI Semantic Convention Recording Functions
|
|
504
|
+
export function recordGenAiClientTokenUsage(config, tokenCount, attributes) {
|
|
505
|
+
if (!genAiClientTokenUsageHistogram || !isMetricsInitialized)
|
|
506
|
+
return;
|
|
507
|
+
const metricAttributes = {
|
|
508
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
509
|
+
...attributes,
|
|
510
|
+
};
|
|
511
|
+
genAiClientTokenUsageHistogram.record(tokenCount, metricAttributes);
|
|
512
|
+
}
|
|
513
|
+
export function recordGenAiClientOperationDuration(config, durationSeconds, attributes) {
|
|
514
|
+
if (!genAiClientOperationDurationHistogram || !isMetricsInitialized)
|
|
515
|
+
return;
|
|
516
|
+
const metricAttributes = {
|
|
517
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
518
|
+
...attributes,
|
|
519
|
+
};
|
|
520
|
+
genAiClientOperationDurationHistogram.record(durationSeconds, metricAttributes);
|
|
521
|
+
}
|
|
522
|
+
export function getConventionAttributes(event) {
|
|
523
|
+
const operationName = getGenAiOperationName();
|
|
524
|
+
const provider = getGenAiProvider(event.auth_type);
|
|
525
|
+
return {
|
|
526
|
+
'gen_ai.operation.name': operationName,
|
|
527
|
+
'gen_ai.provider.name': provider,
|
|
528
|
+
'gen_ai.request.model': event.model,
|
|
529
|
+
'gen_ai.response.model': event.model,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Maps authentication type to GenAI provider name following OpenTelemetry conventions
|
|
534
|
+
*/
|
|
535
|
+
function getGenAiProvider(authType) {
|
|
536
|
+
switch (authType) {
|
|
537
|
+
case AuthType.USE_VERTEX_AI:
|
|
538
|
+
case AuthType.CLOUD_SHELL:
|
|
539
|
+
case AuthType.LOGIN_WITH_GOOGLE:
|
|
540
|
+
return GenAiProviderName.GCP_VERTEX_AI;
|
|
541
|
+
case AuthType.USE_GEMINI:
|
|
542
|
+
default:
|
|
543
|
+
return GenAiProviderName.GCP_GEN_AI;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function getGenAiOperationName() {
|
|
547
|
+
return GenAiOperationName.GENERATE_CONTENT;
|
|
548
|
+
}
|
|
292
549
|
// Performance Monitoring Functions
|
|
293
550
|
export function initializePerformanceMonitoring(config) {
|
|
294
551
|
const meter = getMeter();
|
|
@@ -300,178 +557,149 @@ export function initializePerformanceMonitoring(config) {
|
|
|
300
557
|
isPerformanceMonitoringEnabled = config.getTelemetryEnabled();
|
|
301
558
|
if (!isPerformanceMonitoringEnabled)
|
|
302
559
|
return;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
description: 'CLI startup time in milliseconds, broken down by initialization phase.',
|
|
306
|
-
unit: 'ms',
|
|
307
|
-
valueType: ValueType.DOUBLE,
|
|
308
|
-
});
|
|
309
|
-
// Initialize memory usage histogram (using histogram until ObservableGauge is available)
|
|
310
|
-
memoryUsageGauge = meter.createHistogram(METRIC_MEMORY_USAGE, {
|
|
311
|
-
description: 'Memory usage in bytes.',
|
|
312
|
-
unit: 'bytes',
|
|
313
|
-
valueType: ValueType.INT,
|
|
314
|
-
});
|
|
315
|
-
// Initialize CPU usage histogram
|
|
316
|
-
cpuUsageGauge = meter.createHistogram(METRIC_CPU_USAGE, {
|
|
317
|
-
description: 'CPU usage percentage.',
|
|
318
|
-
unit: 'percent',
|
|
319
|
-
valueType: ValueType.DOUBLE,
|
|
320
|
-
});
|
|
321
|
-
// Initialize tool queue depth histogram
|
|
322
|
-
toolQueueDepthGauge = meter.createHistogram(METRIC_TOOL_QUEUE_DEPTH, {
|
|
323
|
-
description: 'Number of tools in execution queue.',
|
|
324
|
-
valueType: ValueType.INT,
|
|
325
|
-
});
|
|
326
|
-
// Initialize performance breakdowns
|
|
327
|
-
toolExecutionBreakdownHistogram = meter.createHistogram(METRIC_TOOL_EXECUTION_BREAKDOWN, {
|
|
328
|
-
description: 'Tool execution time breakdown by phase in milliseconds.',
|
|
329
|
-
unit: 'ms',
|
|
330
|
-
valueType: ValueType.INT,
|
|
331
|
-
});
|
|
332
|
-
tokenEfficiencyHistogram = meter.createHistogram(METRIC_TOKEN_EFFICIENCY, {
|
|
333
|
-
description: 'Token efficiency metrics (tokens per operation, cache hit rate, etc.).',
|
|
334
|
-
valueType: ValueType.DOUBLE,
|
|
335
|
-
});
|
|
336
|
-
apiRequestBreakdownHistogram = meter.createHistogram(METRIC_API_REQUEST_BREAKDOWN, {
|
|
337
|
-
description: 'API request time breakdown by phase in milliseconds.',
|
|
338
|
-
unit: 'ms',
|
|
339
|
-
valueType: ValueType.INT,
|
|
340
|
-
});
|
|
341
|
-
// Initialize performance score and regression detection
|
|
342
|
-
performanceScoreGauge = meter.createHistogram(METRIC_PERFORMANCE_SCORE, {
|
|
343
|
-
description: 'Composite performance score (0-100).',
|
|
344
|
-
unit: 'score',
|
|
345
|
-
valueType: ValueType.DOUBLE,
|
|
346
|
-
});
|
|
347
|
-
regressionDetectionCounter = meter.createCounter(METRIC_REGRESSION_DETECTION, {
|
|
348
|
-
description: 'Performance regression detection events.',
|
|
349
|
-
valueType: ValueType.INT,
|
|
560
|
+
Object.entries(PERFORMANCE_COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
561
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
350
562
|
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
unit: 'percent',
|
|
354
|
-
valueType: ValueType.DOUBLE,
|
|
355
|
-
});
|
|
356
|
-
baselineComparisonHistogram = meter.createHistogram(METRIC_BASELINE_COMPARISON, {
|
|
357
|
-
description: 'Performance comparison to established baseline (percentage change).',
|
|
358
|
-
unit: 'percent',
|
|
359
|
-
valueType: ValueType.DOUBLE,
|
|
563
|
+
Object.entries(PERFORMANCE_HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
564
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
360
565
|
});
|
|
361
566
|
}
|
|
362
|
-
export function recordStartupPerformance(config,
|
|
567
|
+
export function recordStartupPerformance(config, durationMs, attributes) {
|
|
363
568
|
if (!startupTimeHistogram || !isPerformanceMonitoringEnabled)
|
|
364
569
|
return;
|
|
365
|
-
const
|
|
366
|
-
...getCommonAttributes(config),
|
|
367
|
-
phase,
|
|
368
|
-
...details,
|
|
570
|
+
const metricAttributes = {
|
|
571
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
572
|
+
phase: attributes.phase,
|
|
573
|
+
...attributes.details,
|
|
369
574
|
};
|
|
370
|
-
startupTimeHistogram.record(durationMs,
|
|
575
|
+
startupTimeHistogram.record(durationMs, metricAttributes);
|
|
371
576
|
}
|
|
372
|
-
export function recordMemoryUsage(config,
|
|
577
|
+
export function recordMemoryUsage(config, bytes, attributes) {
|
|
373
578
|
if (!memoryUsageGauge || !isPerformanceMonitoringEnabled)
|
|
374
579
|
return;
|
|
375
|
-
const
|
|
376
|
-
...getCommonAttributes(config),
|
|
377
|
-
|
|
378
|
-
component,
|
|
580
|
+
const metricAttributes = {
|
|
581
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
582
|
+
...attributes,
|
|
379
583
|
};
|
|
380
|
-
memoryUsageGauge.record(bytes,
|
|
584
|
+
memoryUsageGauge.record(bytes, metricAttributes);
|
|
381
585
|
}
|
|
382
|
-
export function recordCpuUsage(config, percentage,
|
|
586
|
+
export function recordCpuUsage(config, percentage, attributes) {
|
|
383
587
|
if (!cpuUsageGauge || !isPerformanceMonitoringEnabled)
|
|
384
588
|
return;
|
|
385
|
-
const
|
|
386
|
-
...getCommonAttributes(config),
|
|
387
|
-
|
|
589
|
+
const metricAttributes = {
|
|
590
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
591
|
+
...attributes,
|
|
388
592
|
};
|
|
389
|
-
cpuUsageGauge.record(percentage,
|
|
593
|
+
cpuUsageGauge.record(percentage, metricAttributes);
|
|
390
594
|
}
|
|
391
595
|
export function recordToolQueueDepth(config, queueDepth) {
|
|
392
596
|
if (!toolQueueDepthGauge || !isPerformanceMonitoringEnabled)
|
|
393
597
|
return;
|
|
394
598
|
const attributes = {
|
|
395
|
-
...getCommonAttributes(config),
|
|
599
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
396
600
|
};
|
|
397
601
|
toolQueueDepthGauge.record(queueDepth, attributes);
|
|
398
602
|
}
|
|
399
|
-
export function recordToolExecutionBreakdown(config,
|
|
603
|
+
export function recordToolExecutionBreakdown(config, durationMs, attributes) {
|
|
400
604
|
if (!toolExecutionBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
401
605
|
return;
|
|
402
|
-
const
|
|
403
|
-
...getCommonAttributes(config),
|
|
404
|
-
|
|
405
|
-
phase,
|
|
606
|
+
const metricAttributes = {
|
|
607
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
608
|
+
...attributes,
|
|
406
609
|
};
|
|
407
|
-
toolExecutionBreakdownHistogram.record(durationMs,
|
|
610
|
+
toolExecutionBreakdownHistogram.record(durationMs, metricAttributes);
|
|
408
611
|
}
|
|
409
|
-
export function recordTokenEfficiency(config,
|
|
612
|
+
export function recordTokenEfficiency(config, value, attributes) {
|
|
410
613
|
if (!tokenEfficiencyHistogram || !isPerformanceMonitoringEnabled)
|
|
411
614
|
return;
|
|
412
|
-
const
|
|
413
|
-
...getCommonAttributes(config),
|
|
414
|
-
|
|
415
|
-
metric,
|
|
416
|
-
context,
|
|
615
|
+
const metricAttributes = {
|
|
616
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
617
|
+
...attributes,
|
|
417
618
|
};
|
|
418
|
-
tokenEfficiencyHistogram.record(value,
|
|
619
|
+
tokenEfficiencyHistogram.record(value, metricAttributes);
|
|
419
620
|
}
|
|
420
|
-
export function recordApiRequestBreakdown(config,
|
|
621
|
+
export function recordApiRequestBreakdown(config, durationMs, attributes) {
|
|
421
622
|
if (!apiRequestBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
422
623
|
return;
|
|
423
|
-
const
|
|
424
|
-
...getCommonAttributes(config),
|
|
425
|
-
|
|
426
|
-
phase,
|
|
624
|
+
const metricAttributes = {
|
|
625
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
626
|
+
...attributes,
|
|
427
627
|
};
|
|
428
|
-
apiRequestBreakdownHistogram.record(durationMs,
|
|
628
|
+
apiRequestBreakdownHistogram.record(durationMs, metricAttributes);
|
|
429
629
|
}
|
|
430
|
-
export function recordPerformanceScore(config, score,
|
|
630
|
+
export function recordPerformanceScore(config, score, attributes) {
|
|
431
631
|
if (!performanceScoreGauge || !isPerformanceMonitoringEnabled)
|
|
432
632
|
return;
|
|
433
|
-
const
|
|
434
|
-
...getCommonAttributes(config),
|
|
435
|
-
|
|
436
|
-
baseline,
|
|
633
|
+
const metricAttributes = {
|
|
634
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
635
|
+
...attributes,
|
|
437
636
|
};
|
|
438
|
-
performanceScoreGauge.record(score,
|
|
637
|
+
performanceScoreGauge.record(score, metricAttributes);
|
|
439
638
|
}
|
|
440
|
-
export function recordPerformanceRegression(config,
|
|
639
|
+
export function recordPerformanceRegression(config, attributes) {
|
|
441
640
|
if (!regressionDetectionCounter || !isPerformanceMonitoringEnabled)
|
|
442
641
|
return;
|
|
443
|
-
const
|
|
444
|
-
...getCommonAttributes(config),
|
|
445
|
-
|
|
446
|
-
severity,
|
|
447
|
-
current_value: currentValue,
|
|
448
|
-
baseline_value: baselineValue,
|
|
642
|
+
const metricAttributes = {
|
|
643
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
644
|
+
...attributes,
|
|
449
645
|
};
|
|
450
|
-
regressionDetectionCounter.add(1,
|
|
451
|
-
if (
|
|
452
|
-
const percentageChange = ((
|
|
453
|
-
|
|
646
|
+
regressionDetectionCounter.add(1, metricAttributes);
|
|
647
|
+
if (attributes.baseline_value !== 0 && regressionPercentageChangeHistogram) {
|
|
648
|
+
const percentageChange = ((attributes.current_value - attributes.baseline_value) /
|
|
649
|
+
attributes.baseline_value) *
|
|
650
|
+
100;
|
|
651
|
+
regressionPercentageChangeHistogram.record(percentageChange, metricAttributes);
|
|
454
652
|
}
|
|
455
653
|
}
|
|
456
|
-
export function recordBaselineComparison(config,
|
|
654
|
+
export function recordBaselineComparison(config, attributes) {
|
|
457
655
|
if (!baselineComparisonHistogram || !isPerformanceMonitoringEnabled)
|
|
458
656
|
return;
|
|
459
|
-
if (
|
|
657
|
+
if (attributes.baseline_value === 0) {
|
|
460
658
|
diag.warn('Baseline value is zero, skipping comparison.');
|
|
461
659
|
return;
|
|
462
660
|
}
|
|
463
|
-
const percentageChange = ((
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
baseline_value: baselineValue,
|
|
661
|
+
const percentageChange = ((attributes.current_value - attributes.baseline_value) /
|
|
662
|
+
attributes.baseline_value) *
|
|
663
|
+
100;
|
|
664
|
+
const metricAttributes = {
|
|
665
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
666
|
+
...attributes,
|
|
470
667
|
};
|
|
471
|
-
baselineComparisonHistogram.record(percentageChange,
|
|
668
|
+
baselineComparisonHistogram.record(percentageChange, metricAttributes);
|
|
472
669
|
}
|
|
473
670
|
// Utility function to check if performance monitoring is enabled
|
|
474
671
|
export function isPerformanceMonitoringActive() {
|
|
475
672
|
return isPerformanceMonitoringEnabled && isMetricsInitialized;
|
|
476
673
|
}
|
|
674
|
+
/**
|
|
675
|
+
* Token usage recording that emits both custom and convention metrics.
|
|
676
|
+
*/
|
|
677
|
+
export function recordTokenUsageMetrics(config, tokenCount, attributes) {
|
|
678
|
+
recordCustomTokenUsageMetrics(config, tokenCount, {
|
|
679
|
+
model: attributes.model,
|
|
680
|
+
type: attributes.type,
|
|
681
|
+
});
|
|
682
|
+
if ((attributes.type === 'input' || attributes.type === 'output') &&
|
|
683
|
+
attributes.genAiAttributes) {
|
|
684
|
+
recordGenAiClientTokenUsage(config, tokenCount, {
|
|
685
|
+
...attributes.genAiAttributes,
|
|
686
|
+
'gen_ai.token.type': attributes.type,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Operation latency recording that emits both custom and convention metrics.
|
|
692
|
+
*/
|
|
693
|
+
export function recordApiResponseMetrics(config, durationMs, attributes) {
|
|
694
|
+
recordCustomApiResponseMetrics(config, durationMs, {
|
|
695
|
+
model: attributes.model,
|
|
696
|
+
status_code: attributes.status_code,
|
|
697
|
+
});
|
|
698
|
+
if (attributes.genAiAttributes) {
|
|
699
|
+
const durationSeconds = durationMs / 1000;
|
|
700
|
+
recordGenAiClientOperationDuration(config, durationSeconds, {
|
|
701
|
+
...attributes.genAiAttributes,
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
477
705
|
//# sourceMappingURL=metrics.js.map
|