@google/gemini-cli-core 0.0.8999999 → 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 +105 -62
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- 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 +46 -15
- package/dist/src/config/config.js +106 -27
- 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/constants.d.ts +11 -0
- package/dist/src/config/constants.js +16 -0
- package/dist/src/config/constants.js.map +1 -0
- 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.d.ts +4 -0
- package/dist/src/core/baseLlmClient.js +24 -23
- package/dist/src/core/baseLlmClient.js.map +1 -1
- package/dist/src/core/baseLlmClient.test.js +76 -13
- 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 -47
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +385 -134
- 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 +24 -15
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +359 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +11 -14
- package/dist/src/core/geminiChat.js +75 -124
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +260 -239
- 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 +93 -18
- 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 +15 -6
- package/dist/src/core/turn.js +14 -13
- 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/generated/git-commit.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +5 -2
- package/dist/src/ide/detect-ide.js +11 -2
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +34 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +2 -1
- package/dist/src/ide/ide-client.js +25 -20
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +6 -6
- package/dist/src/ide/ide-client.test.js.map +1 -1
- 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 +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +1 -0
- package/dist/src/mcp/oauth-provider.js +19 -14
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +137 -1
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.js +1 -0
- package/dist/src/mcp/oauth-utils.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/routing/strategies/compositeStrategy.js +4 -3
- package/dist/src/routing/strategies/compositeStrategy.js.map +1 -1
- package/dist/src/services/chatRecordingService.d.ts +3 -2
- package/dist/src/services/chatRecordingService.js +3 -2
- 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 +18 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +156 -11
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +226 -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 +19 -3
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +44 -5
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/config.d.ts +31 -0
- package/dist/src/telemetry/config.js +76 -0
- package/dist/src/telemetry/config.js.map +1 -0
- package/dist/src/telemetry/config.test.d.ts +6 -0
- package/dist/src/telemetry/config.test.js +124 -0
- package/dist/src/telemetry/config.test.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +0 -34
- package/dist/src/telemetry/constants.js +0 -34
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +6 -2
- package/dist/src/telemetry/index.js +17 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +10 -2
- package/dist/src/telemetry/loggers.js +206 -273
- 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 +260 -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 +436 -11
- package/dist/src/telemetry/metrics.js +600 -110
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +898 -16
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/sdk.js +4 -1
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/sdk.test.js +13 -0
- package/dist/src/telemetry/sdk.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 +167 -5
- package/dist/src/telemetry/types.js +692 -35
- 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/edit.js +6 -0
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +41 -0
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.js +4 -2
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/ls.js +1 -1
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +5 -14
- package/dist/src/tools/mcp-client.js +50 -97
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +175 -157
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.js +30 -2
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +117 -0
- package/dist/src/tools/mcp-tool.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/message-bus-integration.test.d.ts +6 -0
- package/dist/src/tools/message-bus-integration.test.js +183 -0
- package/dist/src/tools/message-bus-integration.test.js.map +1 -0
- package/dist/src/tools/shell.js +60 -4
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +2 -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 +122 -12
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +136 -29
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +22 -0
- package/dist/src/tools/tool-error.js +28 -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/tools.d.ts +11 -3
- package/dist/src/tools/tools.js +94 -3
- package/dist/src/tools/tools.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 +25 -0
- package/dist/src/tools/write-todos.js +151 -0
- package/dist/src/tools/write-todos.js.map +1 -0
- package/dist/src/tools/write-todos.test.d.ts +6 -0
- package/dist/src/tools/write-todos.test.js +89 -0
- package/dist/src/tools/write-todos.test.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +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.d.ts +1 -1
- package/dist/src/utils/getFolderStructure.js +1 -1
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- 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 +14 -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 +2 -1
- package/dist/src/utils/memoryDiscovery.js +3 -2
- 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 +60 -162
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +105 -135
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/schemaValidator.js +11 -1
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/schemaValidator.test.d.ts +6 -0
- package/dist/src/utils/schemaValidator.test.js +113 -0
- package/dist/src/utils/schemaValidator.test.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +1 -0
- package/dist/src/utils/shell-utils.js +6 -2
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +5 -0
- package/dist/src/utils/shell-utils.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/thoughtUtils.d.ts +21 -0
- package/dist/src/utils/thoughtUtils.js +39 -0
- package/dist/src/utils/thoughtUtils.js.map +1 -0
- package/dist/src/utils/thoughtUtils.test.d.ts +6 -0
- package/dist/src/utils/thoughtUtils.test.js +78 -0
- package/dist/src/utils/thoughtUtils.test.js.map +1 -0
- package/dist/src/utils/tool-utils.js +2 -2
- package/dist/src/utils/tool-utils.js.map +1 -1
- package/dist/src/utils/tool-utils.test.js +8 -0
- package/dist/src/utils/tool-utils.test.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 +2 -2
- 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
|
@@ -3,20 +3,315 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { metrics, ValueType } from '@opentelemetry/api';
|
|
7
|
-
import { SERVICE_NAME
|
|
6
|
+
import { diag, metrics, ValueType } from '@opentelemetry/api';
|
|
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';
|
|
31
|
+
// Performance Monitoring Metrics
|
|
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
|
+
};
|
|
8
258
|
export var FileOperation;
|
|
9
259
|
(function (FileOperation) {
|
|
10
260
|
FileOperation["CREATE"] = "create";
|
|
11
261
|
FileOperation["READ"] = "read";
|
|
12
262
|
FileOperation["UPDATE"] = "update";
|
|
13
263
|
})(FileOperation || (FileOperation = {}));
|
|
264
|
+
export var PerformanceMetricType;
|
|
265
|
+
(function (PerformanceMetricType) {
|
|
266
|
+
PerformanceMetricType["STARTUP"] = "startup";
|
|
267
|
+
PerformanceMetricType["MEMORY"] = "memory";
|
|
268
|
+
PerformanceMetricType["CPU"] = "cpu";
|
|
269
|
+
PerformanceMetricType["TOOL_EXECUTION"] = "tool_execution";
|
|
270
|
+
PerformanceMetricType["API_REQUEST"] = "api_request";
|
|
271
|
+
PerformanceMetricType["TOKEN_EFFICIENCY"] = "token_efficiency";
|
|
272
|
+
})(PerformanceMetricType || (PerformanceMetricType = {}));
|
|
273
|
+
export var MemoryMetricType;
|
|
274
|
+
(function (MemoryMetricType) {
|
|
275
|
+
MemoryMetricType["HEAP_USED"] = "heap_used";
|
|
276
|
+
MemoryMetricType["HEAP_TOTAL"] = "heap_total";
|
|
277
|
+
MemoryMetricType["EXTERNAL"] = "external";
|
|
278
|
+
MemoryMetricType["RSS"] = "rss";
|
|
279
|
+
})(MemoryMetricType || (MemoryMetricType = {}));
|
|
280
|
+
export var ToolExecutionPhase;
|
|
281
|
+
(function (ToolExecutionPhase) {
|
|
282
|
+
ToolExecutionPhase["VALIDATION"] = "validation";
|
|
283
|
+
ToolExecutionPhase["PREPARATION"] = "preparation";
|
|
284
|
+
ToolExecutionPhase["EXECUTION"] = "execution";
|
|
285
|
+
ToolExecutionPhase["RESULT_PROCESSING"] = "result_processing";
|
|
286
|
+
})(ToolExecutionPhase || (ToolExecutionPhase = {}));
|
|
287
|
+
export var ApiRequestPhase;
|
|
288
|
+
(function (ApiRequestPhase) {
|
|
289
|
+
ApiRequestPhase["REQUEST_PREPARATION"] = "request_preparation";
|
|
290
|
+
ApiRequestPhase["NETWORK_LATENCY"] = "network_latency";
|
|
291
|
+
ApiRequestPhase["RESPONSE_PROCESSING"] = "response_processing";
|
|
292
|
+
ApiRequestPhase["TOKEN_PROCESSING"] = "token_processing";
|
|
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 = {}));
|
|
14
308
|
let cliMeter;
|
|
15
309
|
let toolCallCounter;
|
|
16
310
|
let toolCallLatencyHistogram;
|
|
17
311
|
let apiRequestCounter;
|
|
18
312
|
let apiRequestLatencyHistogram;
|
|
19
313
|
let tokenUsageCounter;
|
|
314
|
+
let sessionCounter;
|
|
20
315
|
let fileOperationCounter;
|
|
21
316
|
let chatCompressionCounter;
|
|
22
317
|
let invalidChunkCounter;
|
|
@@ -24,12 +319,28 @@ let contentRetryCounter;
|
|
|
24
319
|
let contentRetryFailureCounter;
|
|
25
320
|
let modelRoutingLatencyHistogram;
|
|
26
321
|
let modelRoutingFailureCounter;
|
|
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;
|
|
330
|
+
// Performance Monitoring Metrics
|
|
331
|
+
let startupTimeHistogram;
|
|
332
|
+
let memoryUsageGauge; // Using Histogram until ObservableGauge is available
|
|
333
|
+
let cpuUsageGauge;
|
|
334
|
+
let toolQueueDepthGauge;
|
|
335
|
+
let toolExecutionBreakdownHistogram;
|
|
336
|
+
let tokenEfficiencyHistogram;
|
|
337
|
+
let apiRequestBreakdownHistogram;
|
|
338
|
+
let performanceScoreGauge;
|
|
339
|
+
let regressionDetectionCounter;
|
|
340
|
+
let regressionPercentageChangeHistogram;
|
|
341
|
+
let baselineComparisonHistogram;
|
|
27
342
|
let isMetricsInitialized = false;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
'session.id': config.getSessionId(),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
343
|
+
let isPerformanceMonitoringEnabled = false;
|
|
33
344
|
export function getMeter() {
|
|
34
345
|
if (!cliMeter) {
|
|
35
346
|
cliMeter = metrics.getMeter(SERVICE_NAME);
|
|
@@ -42,157 +353,105 @@ export function initializeMetrics(config) {
|
|
|
42
353
|
const meter = getMeter();
|
|
43
354
|
if (!meter)
|
|
44
355
|
return;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
valueType
|
|
48
|
-
});
|
|
49
|
-
toolCallLatencyHistogram = meter.createHistogram(METRIC_TOOL_CALL_LATENCY, {
|
|
50
|
-
description: 'Latency of tool calls in milliseconds.',
|
|
51
|
-
unit: 'ms',
|
|
52
|
-
valueType: ValueType.INT,
|
|
356
|
+
// Initialize core metrics
|
|
357
|
+
Object.entries(COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
358
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
53
359
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
valueType: ValueType.INT,
|
|
360
|
+
Object.entries(HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
361
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
57
362
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
tokenUsageCounter = meter.createCounter(METRIC_TOKEN_USAGE, {
|
|
64
|
-
description: 'Counts the total number of tokens used.',
|
|
65
|
-
valueType: ValueType.INT,
|
|
66
|
-
});
|
|
67
|
-
fileOperationCounter = meter.createCounter(METRIC_FILE_OPERATION_COUNT, {
|
|
68
|
-
description: 'Counts file operations (create, read, update).',
|
|
69
|
-
valueType: ValueType.INT,
|
|
70
|
-
});
|
|
71
|
-
chatCompressionCounter = meter.createCounter(EVENT_CHAT_COMPRESSION, {
|
|
72
|
-
description: 'Counts chat compression events.',
|
|
73
|
-
valueType: ValueType.INT,
|
|
74
|
-
});
|
|
75
|
-
// New counters for content errors
|
|
76
|
-
invalidChunkCounter = meter.createCounter(METRIC_INVALID_CHUNK_COUNT, {
|
|
77
|
-
description: 'Counts invalid chunks received from a stream.',
|
|
78
|
-
valueType: ValueType.INT,
|
|
79
|
-
});
|
|
80
|
-
contentRetryCounter = meter.createCounter(METRIC_CONTENT_RETRY_COUNT, {
|
|
81
|
-
description: 'Counts retries due to content errors (e.g., empty stream).',
|
|
82
|
-
valueType: ValueType.INT,
|
|
83
|
-
});
|
|
84
|
-
contentRetryFailureCounter = meter.createCounter(METRIC_CONTENT_RETRY_FAILURE_COUNT, {
|
|
85
|
-
description: 'Counts occurrences of all content retries failing.',
|
|
86
|
-
valueType: ValueType.INT,
|
|
87
|
-
});
|
|
88
|
-
modelRoutingLatencyHistogram = meter.createHistogram(METRIC_MODEL_ROUTING_LATENCY, {
|
|
89
|
-
description: 'Latency of model routing decisions in milliseconds.',
|
|
90
|
-
unit: 'ms',
|
|
91
|
-
valueType: ValueType.INT,
|
|
92
|
-
});
|
|
93
|
-
modelRoutingFailureCounter = meter.createCounter(METRIC_MODEL_ROUTING_FAILURE_COUNT, {
|
|
94
|
-
description: 'Counts model routing failures.',
|
|
95
|
-
valueType: ValueType.INT,
|
|
96
|
-
});
|
|
97
|
-
const sessionCounter = meter.createCounter(METRIC_SESSION_COUNT, {
|
|
98
|
-
description: 'Count of CLI sessions started.',
|
|
99
|
-
valueType: ValueType.INT,
|
|
100
|
-
});
|
|
101
|
-
sessionCounter.add(1, getCommonAttributes(config));
|
|
363
|
+
// Increment session counter after all metrics are initialized
|
|
364
|
+
sessionCounter?.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
365
|
+
// Initialize performance monitoring metrics if enabled
|
|
366
|
+
initializePerformanceMonitoring(config);
|
|
102
367
|
isMetricsInitialized = true;
|
|
103
368
|
}
|
|
104
|
-
export function recordChatCompressionMetrics(config,
|
|
369
|
+
export function recordChatCompressionMetrics(config, attributes) {
|
|
105
370
|
if (!chatCompressionCounter || !isMetricsInitialized)
|
|
106
371
|
return;
|
|
107
372
|
chatCompressionCounter.add(1, {
|
|
108
|
-
...getCommonAttributes(config),
|
|
109
|
-
...
|
|
373
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
374
|
+
...attributes,
|
|
110
375
|
});
|
|
111
376
|
}
|
|
112
|
-
export function recordToolCallMetrics(config,
|
|
377
|
+
export function recordToolCallMetrics(config, durationMs, attributes) {
|
|
113
378
|
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
|
|
114
379
|
return;
|
|
115
380
|
const metricAttributes = {
|
|
116
|
-
...getCommonAttributes(config),
|
|
117
|
-
|
|
118
|
-
success,
|
|
119
|
-
decision,
|
|
120
|
-
tool_type,
|
|
381
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
382
|
+
...attributes,
|
|
121
383
|
};
|
|
122
384
|
toolCallCounter.add(1, metricAttributes);
|
|
123
385
|
toolCallLatencyHistogram.record(durationMs, {
|
|
124
|
-
...getCommonAttributes(config),
|
|
125
|
-
function_name:
|
|
386
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
387
|
+
function_name: attributes.function_name,
|
|
126
388
|
});
|
|
127
389
|
}
|
|
128
|
-
export function
|
|
390
|
+
export function recordCustomTokenUsageMetrics(config, tokenCount, attributes) {
|
|
129
391
|
if (!tokenUsageCounter || !isMetricsInitialized)
|
|
130
392
|
return;
|
|
131
393
|
tokenUsageCounter.add(tokenCount, {
|
|
132
|
-
...getCommonAttributes(config),
|
|
133
|
-
|
|
134
|
-
type,
|
|
394
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
395
|
+
...attributes,
|
|
135
396
|
});
|
|
136
397
|
}
|
|
137
|
-
export function
|
|
398
|
+
export function recordCustomApiResponseMetrics(config, durationMs, attributes) {
|
|
138
399
|
if (!apiRequestCounter ||
|
|
139
400
|
!apiRequestLatencyHistogram ||
|
|
140
401
|
!isMetricsInitialized)
|
|
141
402
|
return;
|
|
142
403
|
const metricAttributes = {
|
|
143
|
-
...getCommonAttributes(config),
|
|
144
|
-
model,
|
|
145
|
-
status_code:
|
|
404
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
405
|
+
model: attributes.model,
|
|
406
|
+
status_code: attributes.status_code ?? 'ok',
|
|
146
407
|
};
|
|
147
408
|
apiRequestCounter.add(1, metricAttributes);
|
|
148
409
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
149
|
-
...getCommonAttributes(config),
|
|
150
|
-
model,
|
|
410
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
411
|
+
model: attributes.model,
|
|
151
412
|
});
|
|
152
413
|
}
|
|
153
|
-
export function recordApiErrorMetrics(config,
|
|
414
|
+
export function recordApiErrorMetrics(config, durationMs, attributes) {
|
|
154
415
|
if (!apiRequestCounter ||
|
|
155
416
|
!apiRequestLatencyHistogram ||
|
|
156
417
|
!isMetricsInitialized)
|
|
157
418
|
return;
|
|
158
419
|
const metricAttributes = {
|
|
159
|
-
...getCommonAttributes(config),
|
|
160
|
-
model,
|
|
161
|
-
status_code:
|
|
162
|
-
error_type:
|
|
420
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
421
|
+
model: attributes.model,
|
|
422
|
+
status_code: attributes.status_code ?? 'error',
|
|
423
|
+
error_type: attributes.error_type ?? 'unknown',
|
|
163
424
|
};
|
|
164
425
|
apiRequestCounter.add(1, metricAttributes);
|
|
165
426
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
166
|
-
...getCommonAttributes(config),
|
|
167
|
-
model,
|
|
427
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
428
|
+
model: attributes.model,
|
|
168
429
|
});
|
|
169
430
|
}
|
|
170
|
-
export function recordFileOperationMetric(config,
|
|
431
|
+
export function recordFileOperationMetric(config, attributes) {
|
|
171
432
|
if (!fileOperationCounter || !isMetricsInitialized)
|
|
172
433
|
return;
|
|
173
|
-
|
|
174
|
-
...getCommonAttributes(config),
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
if (lines !== undefined)
|
|
178
|
-
attributes['lines'] = lines;
|
|
179
|
-
if (mimetype !== undefined)
|
|
180
|
-
attributes['mimetype'] = mimetype;
|
|
181
|
-
if (extension !== undefined)
|
|
182
|
-
attributes['extension'] = extension;
|
|
183
|
-
if (programming_language !== undefined) {
|
|
184
|
-
attributes['programming_language'] = programming_language;
|
|
185
|
-
}
|
|
186
|
-
fileOperationCounter.add(1, attributes);
|
|
434
|
+
fileOperationCounter.add(1, {
|
|
435
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
436
|
+
...attributes,
|
|
437
|
+
});
|
|
187
438
|
}
|
|
188
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
|
+
}
|
|
189
448
|
/**
|
|
190
449
|
* Records a metric for when an invalid chunk is received from a stream.
|
|
191
450
|
*/
|
|
192
451
|
export function recordInvalidChunk(config) {
|
|
193
452
|
if (!invalidChunkCounter || !isMetricsInitialized)
|
|
194
453
|
return;
|
|
195
|
-
invalidChunkCounter.add(1, getCommonAttributes(config));
|
|
454
|
+
invalidChunkCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
196
455
|
}
|
|
197
456
|
/**
|
|
198
457
|
* Records a metric for when a retry is triggered due to a content error.
|
|
@@ -200,7 +459,7 @@ export function recordInvalidChunk(config) {
|
|
|
200
459
|
export function recordContentRetry(config) {
|
|
201
460
|
if (!contentRetryCounter || !isMetricsInitialized)
|
|
202
461
|
return;
|
|
203
|
-
contentRetryCounter.add(1, getCommonAttributes(config));
|
|
462
|
+
contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
204
463
|
}
|
|
205
464
|
/**
|
|
206
465
|
* Records a metric for when all content error retries have failed for a request.
|
|
@@ -208,7 +467,15 @@ export function recordContentRetry(config) {
|
|
|
208
467
|
export function recordContentRetryFailure(config) {
|
|
209
468
|
if (!contentRetryFailureCounter || !isMetricsInitialized)
|
|
210
469
|
return;
|
|
211
|
-
contentRetryFailureCounter.add(1, getCommonAttributes(config));
|
|
470
|
+
contentRetryFailureCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
471
|
+
}
|
|
472
|
+
export function recordModelSlashCommand(config, event) {
|
|
473
|
+
if (!modelSlashCommandCallCounter || !isMetricsInitialized)
|
|
474
|
+
return;
|
|
475
|
+
modelSlashCommandCallCounter.add(1, {
|
|
476
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
477
|
+
'slash_command.model.model_name': event.model_name,
|
|
478
|
+
});
|
|
212
479
|
}
|
|
213
480
|
export function recordModelRoutingMetrics(config, event) {
|
|
214
481
|
if (!modelRoutingLatencyHistogram ||
|
|
@@ -216,16 +483,239 @@ export function recordModelRoutingMetrics(config, event) {
|
|
|
216
483
|
!isMetricsInitialized)
|
|
217
484
|
return;
|
|
218
485
|
modelRoutingLatencyHistogram.record(event.routing_latency_ms, {
|
|
219
|
-
...getCommonAttributes(config),
|
|
486
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
220
487
|
'routing.decision_model': event.decision_model,
|
|
221
488
|
'routing.decision_source': event.decision_source,
|
|
222
489
|
});
|
|
223
490
|
if (event.failed) {
|
|
224
491
|
modelRoutingFailureCounter.add(1, {
|
|
225
|
-
...getCommonAttributes(config),
|
|
492
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
226
493
|
'routing.decision_source': event.decision_source,
|
|
227
494
|
'routing.error_message': event.error_message,
|
|
228
495
|
});
|
|
229
496
|
}
|
|
230
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
|
+
}
|
|
565
|
+
// Performance Monitoring Functions
|
|
566
|
+
export function initializePerformanceMonitoring(config) {
|
|
567
|
+
const meter = getMeter();
|
|
568
|
+
if (!meter)
|
|
569
|
+
return;
|
|
570
|
+
// Check if performance monitoring is enabled in config
|
|
571
|
+
// For now, enable performance monitoring when telemetry is enabled
|
|
572
|
+
// TODO: Add specific performance monitoring settings to config
|
|
573
|
+
isPerformanceMonitoringEnabled = config.getTelemetryEnabled();
|
|
574
|
+
if (!isPerformanceMonitoringEnabled)
|
|
575
|
+
return;
|
|
576
|
+
Object.entries(PERFORMANCE_COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
577
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
578
|
+
});
|
|
579
|
+
Object.entries(PERFORMANCE_HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
580
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
export function recordStartupPerformance(config, durationMs, attributes) {
|
|
584
|
+
if (!startupTimeHistogram || !isPerformanceMonitoringEnabled)
|
|
585
|
+
return;
|
|
586
|
+
const metricAttributes = {
|
|
587
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
588
|
+
phase: attributes.phase,
|
|
589
|
+
...attributes.details,
|
|
590
|
+
};
|
|
591
|
+
startupTimeHistogram.record(durationMs, metricAttributes);
|
|
592
|
+
}
|
|
593
|
+
export function recordMemoryUsage(config, bytes, attributes) {
|
|
594
|
+
if (!memoryUsageGauge || !isPerformanceMonitoringEnabled)
|
|
595
|
+
return;
|
|
596
|
+
const metricAttributes = {
|
|
597
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
598
|
+
...attributes,
|
|
599
|
+
};
|
|
600
|
+
memoryUsageGauge.record(bytes, metricAttributes);
|
|
601
|
+
}
|
|
602
|
+
export function recordCpuUsage(config, percentage, attributes) {
|
|
603
|
+
if (!cpuUsageGauge || !isPerformanceMonitoringEnabled)
|
|
604
|
+
return;
|
|
605
|
+
const metricAttributes = {
|
|
606
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
607
|
+
...attributes,
|
|
608
|
+
};
|
|
609
|
+
cpuUsageGauge.record(percentage, metricAttributes);
|
|
610
|
+
}
|
|
611
|
+
export function recordToolQueueDepth(config, queueDepth) {
|
|
612
|
+
if (!toolQueueDepthGauge || !isPerformanceMonitoringEnabled)
|
|
613
|
+
return;
|
|
614
|
+
const attributes = {
|
|
615
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
616
|
+
};
|
|
617
|
+
toolQueueDepthGauge.record(queueDepth, attributes);
|
|
618
|
+
}
|
|
619
|
+
export function recordToolExecutionBreakdown(config, durationMs, attributes) {
|
|
620
|
+
if (!toolExecutionBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
621
|
+
return;
|
|
622
|
+
const metricAttributes = {
|
|
623
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
624
|
+
...attributes,
|
|
625
|
+
};
|
|
626
|
+
toolExecutionBreakdownHistogram.record(durationMs, metricAttributes);
|
|
627
|
+
}
|
|
628
|
+
export function recordTokenEfficiency(config, value, attributes) {
|
|
629
|
+
if (!tokenEfficiencyHistogram || !isPerformanceMonitoringEnabled)
|
|
630
|
+
return;
|
|
631
|
+
const metricAttributes = {
|
|
632
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
633
|
+
...attributes,
|
|
634
|
+
};
|
|
635
|
+
tokenEfficiencyHistogram.record(value, metricAttributes);
|
|
636
|
+
}
|
|
637
|
+
export function recordApiRequestBreakdown(config, durationMs, attributes) {
|
|
638
|
+
if (!apiRequestBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
639
|
+
return;
|
|
640
|
+
const metricAttributes = {
|
|
641
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
642
|
+
...attributes,
|
|
643
|
+
};
|
|
644
|
+
apiRequestBreakdownHistogram.record(durationMs, metricAttributes);
|
|
645
|
+
}
|
|
646
|
+
export function recordPerformanceScore(config, score, attributes) {
|
|
647
|
+
if (!performanceScoreGauge || !isPerformanceMonitoringEnabled)
|
|
648
|
+
return;
|
|
649
|
+
const metricAttributes = {
|
|
650
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
651
|
+
...attributes,
|
|
652
|
+
};
|
|
653
|
+
performanceScoreGauge.record(score, metricAttributes);
|
|
654
|
+
}
|
|
655
|
+
export function recordPerformanceRegression(config, attributes) {
|
|
656
|
+
if (!regressionDetectionCounter || !isPerformanceMonitoringEnabled)
|
|
657
|
+
return;
|
|
658
|
+
const metricAttributes = {
|
|
659
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
660
|
+
...attributes,
|
|
661
|
+
};
|
|
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);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
export function recordBaselineComparison(config, attributes) {
|
|
671
|
+
if (!baselineComparisonHistogram || !isPerformanceMonitoringEnabled)
|
|
672
|
+
return;
|
|
673
|
+
if (attributes.baseline_value === 0) {
|
|
674
|
+
diag.warn('Baseline value is zero, skipping comparison.');
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const percentageChange = ((attributes.current_value - attributes.baseline_value) /
|
|
678
|
+
attributes.baseline_value) *
|
|
679
|
+
100;
|
|
680
|
+
const metricAttributes = {
|
|
681
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
682
|
+
...attributes,
|
|
683
|
+
};
|
|
684
|
+
baselineComparisonHistogram.record(percentageChange, metricAttributes);
|
|
685
|
+
}
|
|
686
|
+
// Utility function to check if performance monitoring is enabled
|
|
687
|
+
export function isPerformanceMonitoringActive() {
|
|
688
|
+
return isPerformanceMonitoringEnabled && isMetricsInitialized;
|
|
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
|
+
}
|
|
231
721
|
//# sourceMappingURL=metrics.js.map
|