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