@machina.ai/cell-cli-core 1.6.1-rc2 → 1.8.2-rc1
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/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +11 -0
- package/dist/src/agents/codebase-investigator.js +73 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +88 -0
- package/dist/src/agents/executor.js +417 -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 +419 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +43 -0
- package/dist/src/agents/invocation.js +100 -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 +206 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +35 -0
- package/dist/src/agents/registry.js +58 -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 +36 -0
- package/dist/src/agents/subagent-tool-wrapper.js +47 -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 +105 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +116 -0
- package/dist/src/agents/types.js +17 -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/config/config.d.ts +15 -8
- package/dist/src/config/config.js +43 -14
- package/dist/src/config/config.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/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 -2
- package/dist/src/core/client.js +37 -48
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +277 -119
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +33 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +4 -3
- package/dist/src/core/geminiChat.js +55 -61
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +241 -29
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/logger.test.js +16 -16
- 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.js +3 -2
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/turn.d.ts +1 -4
- package/dist/src/core/turn.js +2 -12
- package/dist/src/core/turn.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 +45 -14
- package/dist/src/ide/detect-ide.js +32 -69
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +29 -46
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +4 -4
- package/dist/src/ide/ide-client.js +30 -29
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +8 -21
- package/dist/src/ide/ide-client.test.js.map +1 -1
- package/dist/src/ide/ide-installer.d.ts +2 -2
- package/dist/src/ide/ide-installer.js +7 -9
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +20 -13
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/index.d.ts +5 -2
- package/dist/src/index.js +5 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +4 -1
- package/dist/src/mcp/oauth-provider.js +31 -25
- package/dist/src/mcp/oauth-provider.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/policy/policy-engine.js +11 -2
- package/dist/src/policy/policy-engine.js.map +1 -1
- package/dist/src/policy/policy-engine.test.js +45 -0
- package/dist/src/policy/policy-engine.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 +1 -1
- package/dist/src/services/chatRecordingService.js +1 -1
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +11 -0
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +2 -0
- package/dist/src/services/shellExecutionService.js +48 -7
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +13 -4
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/activity-detector.d.ts +41 -0
- package/dist/src/telemetry/activity-detector.js +61 -0
- package/dist/src/telemetry/activity-detector.js.map +1 -0
- package/dist/src/telemetry/activity-detector.test.d.ts +6 -0
- package/dist/src/telemetry/activity-detector.test.js +136 -0
- package/dist/src/telemetry/activity-detector.test.js.map +1 -0
- package/dist/src/telemetry/activity-types.d.ts +19 -0
- package/dist/src/telemetry/activity-types.js +21 -0
- package/dist/src/telemetry/activity-types.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +6 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +155 -102
- 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 +178 -33
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +108 -100
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +116 -100
- 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 +74 -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 +6 -12
- package/dist/src/telemetry/constants.js +7 -12
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +5 -1
- package/dist/src/telemetry/index.js +10 -0
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +3 -1
- package/dist/src/telemetry/loggers.js +78 -11
- 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 +126 -11
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +309 -11
- package/dist/src/telemetry/metrics.js +424 -110
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +538 -15
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/sdk.js +1 -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/types.d.ts +19 -3
- package/dist/src/telemetry/types.js +37 -6
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +1 -1
- package/dist/src/telemetry/uiTelemetry.js +2 -3
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +13 -13
- 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/ls.js +1 -1
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +2 -12
- package/dist/src/tools/mcp-client.js +22 -65
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +9 -154
- package/dist/src/tools/mcp-client.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 +5 -2
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +19 -0
- package/dist/src/tools/smart-edit.js +105 -3
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +83 -5
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +1 -0
- package/dist/src/tools/tool-error.js +1 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- 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/write-todos.d.ts +25 -0
- package/dist/src/tools/write-todos.js +150 -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/flashFallback.test.js +2 -2
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- 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/llm-edit-fixer.js +11 -1
- 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 -1
- package/dist/src/utils/memoryDiscovery.js +1 -1
- package/dist/src/utils/memoryDiscovery.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/retry.d.ts +3 -1
- package/dist/src/utils/retry.js +20 -5
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +31 -2
- 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.js +5 -1
- 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/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,252 @@
|
|
|
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, EVENT_CHAT_COMPRESSION } from './constants.js';
|
|
8
|
+
const TOOL_CALL_COUNT = 'gemini_cli.tool.call.count';
|
|
9
|
+
const TOOL_CALL_LATENCY = 'gemini_cli.tool.call.latency';
|
|
10
|
+
const API_REQUEST_COUNT = 'gemini_cli.api.request.count';
|
|
11
|
+
const API_REQUEST_LATENCY = 'gemini_cli.api.request.latency';
|
|
12
|
+
const TOKEN_USAGE = 'gemini_cli.token.usage';
|
|
13
|
+
const SESSION_COUNT = 'gemini_cli.session.count';
|
|
14
|
+
const FILE_OPERATION_COUNT = 'gemini_cli.file.operation.count';
|
|
15
|
+
const INVALID_CHUNK_COUNT = 'gemini_cli.chat.invalid_chunk.count';
|
|
16
|
+
const CONTENT_RETRY_COUNT = 'gemini_cli.chat.content_retry.count';
|
|
17
|
+
const CONTENT_RETRY_FAILURE_COUNT = 'gemini_cli.chat.content_retry_failure.count';
|
|
18
|
+
const MODEL_ROUTING_LATENCY = 'gemini_cli.model_routing.latency';
|
|
19
|
+
const MODEL_ROUTING_FAILURE_COUNT = 'gemini_cli.model_routing.failure.count';
|
|
20
|
+
const MODEL_SLASH_COMMAND_CALL_COUNT = 'gemini_cli.slash_command.model.call_count';
|
|
21
|
+
// Performance Monitoring Metrics
|
|
22
|
+
const STARTUP_TIME = 'gemini_cli.startup.duration';
|
|
23
|
+
const MEMORY_USAGE = 'gemini_cli.memory.usage';
|
|
24
|
+
const CPU_USAGE = 'gemini_cli.cpu.usage';
|
|
25
|
+
const TOOL_QUEUE_DEPTH = 'gemini_cli.tool.queue.depth';
|
|
26
|
+
const TOOL_EXECUTION_BREAKDOWN = 'gemini_cli.tool.execution.breakdown';
|
|
27
|
+
const TOKEN_EFFICIENCY = 'gemini_cli.token.efficiency';
|
|
28
|
+
const API_REQUEST_BREAKDOWN = 'gemini_cli.api.request.breakdown';
|
|
29
|
+
const PERFORMANCE_SCORE = 'gemini_cli.performance.score';
|
|
30
|
+
const REGRESSION_DETECTION = 'gemini_cli.performance.regression';
|
|
31
|
+
const REGRESSION_PERCENTAGE_CHANGE = 'gemini_cli.performance.regression.percentage_change';
|
|
32
|
+
const BASELINE_COMPARISON = 'gemini_cli.performance.baseline.comparison';
|
|
33
|
+
const baseMetricDefinition = {
|
|
34
|
+
getCommonAttributes: (config) => ({
|
|
35
|
+
'session.id': config.getSessionId(),
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
const COUNTER_DEFINITIONS = {
|
|
39
|
+
[TOOL_CALL_COUNT]: {
|
|
40
|
+
description: 'Counts tool calls, tagged by function name and success.',
|
|
41
|
+
valueType: ValueType.INT,
|
|
42
|
+
assign: (c) => (toolCallCounter = c),
|
|
43
|
+
attributes: {},
|
|
44
|
+
},
|
|
45
|
+
[API_REQUEST_COUNT]: {
|
|
46
|
+
description: 'Counts API requests, tagged by model and status.',
|
|
47
|
+
valueType: ValueType.INT,
|
|
48
|
+
assign: (c) => (apiRequestCounter = c),
|
|
49
|
+
attributes: {},
|
|
50
|
+
},
|
|
51
|
+
[TOKEN_USAGE]: {
|
|
52
|
+
description: 'Counts the total number of tokens used.',
|
|
53
|
+
valueType: ValueType.INT,
|
|
54
|
+
assign: (c) => (tokenUsageCounter = c),
|
|
55
|
+
attributes: {},
|
|
56
|
+
},
|
|
57
|
+
[SESSION_COUNT]: {
|
|
58
|
+
description: 'Count of CLI sessions started.',
|
|
59
|
+
valueType: ValueType.INT,
|
|
60
|
+
assign: (c) => (sessionCounter = c),
|
|
61
|
+
attributes: {},
|
|
62
|
+
},
|
|
63
|
+
[FILE_OPERATION_COUNT]: {
|
|
64
|
+
description: 'Counts file operations (create, read, update).',
|
|
65
|
+
valueType: ValueType.INT,
|
|
66
|
+
assign: (c) => (fileOperationCounter = c),
|
|
67
|
+
attributes: {},
|
|
68
|
+
},
|
|
69
|
+
[INVALID_CHUNK_COUNT]: {
|
|
70
|
+
description: 'Counts invalid chunks received from a stream.',
|
|
71
|
+
valueType: ValueType.INT,
|
|
72
|
+
assign: (c) => (invalidChunkCounter = c),
|
|
73
|
+
attributes: {},
|
|
74
|
+
},
|
|
75
|
+
[CONTENT_RETRY_COUNT]: {
|
|
76
|
+
description: 'Counts retries due to content errors (e.g., empty stream).',
|
|
77
|
+
valueType: ValueType.INT,
|
|
78
|
+
assign: (c) => (contentRetryCounter = c),
|
|
79
|
+
attributes: {},
|
|
80
|
+
},
|
|
81
|
+
[CONTENT_RETRY_FAILURE_COUNT]: {
|
|
82
|
+
description: 'Counts occurrences of all content retries failing.',
|
|
83
|
+
valueType: ValueType.INT,
|
|
84
|
+
assign: (c) => (contentRetryFailureCounter = c),
|
|
85
|
+
attributes: {},
|
|
86
|
+
},
|
|
87
|
+
[MODEL_ROUTING_FAILURE_COUNT]: {
|
|
88
|
+
description: 'Counts model routing failures.',
|
|
89
|
+
valueType: ValueType.INT,
|
|
90
|
+
assign: (c) => (modelRoutingFailureCounter = c),
|
|
91
|
+
attributes: {},
|
|
92
|
+
},
|
|
93
|
+
[MODEL_SLASH_COMMAND_CALL_COUNT]: {
|
|
94
|
+
description: 'Counts model slash command calls.',
|
|
95
|
+
valueType: ValueType.INT,
|
|
96
|
+
assign: (c) => (modelSlashCommandCallCounter = c),
|
|
97
|
+
attributes: {},
|
|
98
|
+
},
|
|
99
|
+
[EVENT_CHAT_COMPRESSION]: {
|
|
100
|
+
description: 'Counts chat compression events.',
|
|
101
|
+
valueType: ValueType.INT,
|
|
102
|
+
assign: (c) => (chatCompressionCounter = c),
|
|
103
|
+
attributes: {},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const HISTOGRAM_DEFINITIONS = {
|
|
107
|
+
[TOOL_CALL_LATENCY]: {
|
|
108
|
+
description: 'Latency of tool calls in milliseconds.',
|
|
109
|
+
unit: 'ms',
|
|
110
|
+
valueType: ValueType.INT,
|
|
111
|
+
assign: (h) => (toolCallLatencyHistogram = h),
|
|
112
|
+
attributes: {},
|
|
113
|
+
},
|
|
114
|
+
[API_REQUEST_LATENCY]: {
|
|
115
|
+
description: 'Latency of API requests in milliseconds.',
|
|
116
|
+
unit: 'ms',
|
|
117
|
+
valueType: ValueType.INT,
|
|
118
|
+
assign: (h) => (apiRequestLatencyHistogram = h),
|
|
119
|
+
attributes: {},
|
|
120
|
+
},
|
|
121
|
+
[MODEL_ROUTING_LATENCY]: {
|
|
122
|
+
description: 'Latency of model routing decisions in milliseconds.',
|
|
123
|
+
unit: 'ms',
|
|
124
|
+
valueType: ValueType.INT,
|
|
125
|
+
assign: (h) => (modelRoutingLatencyHistogram = h),
|
|
126
|
+
attributes: {},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const PERFORMANCE_COUNTER_DEFINITIONS = {
|
|
130
|
+
[REGRESSION_DETECTION]: {
|
|
131
|
+
description: 'Performance regression detection events.',
|
|
132
|
+
valueType: ValueType.INT,
|
|
133
|
+
assign: (c) => (regressionDetectionCounter = c),
|
|
134
|
+
attributes: {},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
const PERFORMANCE_HISTOGRAM_DEFINITIONS = {
|
|
138
|
+
[STARTUP_TIME]: {
|
|
139
|
+
description: 'CLI startup time in milliseconds, broken down by initialization phase.',
|
|
140
|
+
unit: 'ms',
|
|
141
|
+
valueType: ValueType.DOUBLE,
|
|
142
|
+
assign: (h) => (startupTimeHistogram = h),
|
|
143
|
+
attributes: {},
|
|
144
|
+
},
|
|
145
|
+
[MEMORY_USAGE]: {
|
|
146
|
+
description: 'Memory usage in bytes.',
|
|
147
|
+
unit: 'bytes',
|
|
148
|
+
valueType: ValueType.INT,
|
|
149
|
+
assign: (h) => (memoryUsageGauge = h),
|
|
150
|
+
attributes: {},
|
|
151
|
+
},
|
|
152
|
+
[CPU_USAGE]: {
|
|
153
|
+
description: 'CPU usage percentage.',
|
|
154
|
+
unit: 'percent',
|
|
155
|
+
valueType: ValueType.DOUBLE,
|
|
156
|
+
assign: (h) => (cpuUsageGauge = h),
|
|
157
|
+
attributes: {},
|
|
158
|
+
},
|
|
159
|
+
[TOOL_QUEUE_DEPTH]: {
|
|
160
|
+
description: 'Number of tools in execution queue.',
|
|
161
|
+
unit: 'count',
|
|
162
|
+
valueType: ValueType.INT,
|
|
163
|
+
assign: (h) => (toolQueueDepthGauge = h),
|
|
164
|
+
attributes: {},
|
|
165
|
+
},
|
|
166
|
+
[TOOL_EXECUTION_BREAKDOWN]: {
|
|
167
|
+
description: 'Tool execution time breakdown by phase in milliseconds.',
|
|
168
|
+
unit: 'ms',
|
|
169
|
+
valueType: ValueType.INT,
|
|
170
|
+
assign: (h) => (toolExecutionBreakdownHistogram = h),
|
|
171
|
+
attributes: {},
|
|
172
|
+
},
|
|
173
|
+
[TOKEN_EFFICIENCY]: {
|
|
174
|
+
description: 'Token efficiency metrics (tokens per operation, cache hit rate, etc.).',
|
|
175
|
+
unit: 'ratio',
|
|
176
|
+
valueType: ValueType.DOUBLE,
|
|
177
|
+
assign: (h) => (tokenEfficiencyHistogram = h),
|
|
178
|
+
attributes: {},
|
|
179
|
+
},
|
|
180
|
+
[API_REQUEST_BREAKDOWN]: {
|
|
181
|
+
description: 'API request time breakdown by phase in milliseconds.',
|
|
182
|
+
unit: 'ms',
|
|
183
|
+
valueType: ValueType.INT,
|
|
184
|
+
assign: (h) => (apiRequestBreakdownHistogram = h),
|
|
185
|
+
attributes: {},
|
|
186
|
+
},
|
|
187
|
+
[PERFORMANCE_SCORE]: {
|
|
188
|
+
description: 'Composite performance score (0-100).',
|
|
189
|
+
unit: 'score',
|
|
190
|
+
valueType: ValueType.DOUBLE,
|
|
191
|
+
assign: (h) => (performanceScoreGauge = h),
|
|
192
|
+
attributes: {},
|
|
193
|
+
},
|
|
194
|
+
[REGRESSION_PERCENTAGE_CHANGE]: {
|
|
195
|
+
description: 'Percentage change compared to baseline for detected regressions.',
|
|
196
|
+
unit: 'percent',
|
|
197
|
+
valueType: ValueType.DOUBLE,
|
|
198
|
+
assign: (h) => (regressionPercentageChangeHistogram = h),
|
|
199
|
+
attributes: {},
|
|
200
|
+
},
|
|
201
|
+
[BASELINE_COMPARISON]: {
|
|
202
|
+
description: 'Performance comparison to established baseline (percentage change).',
|
|
203
|
+
unit: 'percent',
|
|
204
|
+
valueType: ValueType.DOUBLE,
|
|
205
|
+
assign: (h) => (baselineComparisonHistogram = h),
|
|
206
|
+
attributes: {},
|
|
207
|
+
},
|
|
208
|
+
};
|
|
8
209
|
export var FileOperation;
|
|
9
210
|
(function (FileOperation) {
|
|
10
211
|
FileOperation["CREATE"] = "create";
|
|
11
212
|
FileOperation["READ"] = "read";
|
|
12
213
|
FileOperation["UPDATE"] = "update";
|
|
13
214
|
})(FileOperation || (FileOperation = {}));
|
|
215
|
+
export var PerformanceMetricType;
|
|
216
|
+
(function (PerformanceMetricType) {
|
|
217
|
+
PerformanceMetricType["STARTUP"] = "startup";
|
|
218
|
+
PerformanceMetricType["MEMORY"] = "memory";
|
|
219
|
+
PerformanceMetricType["CPU"] = "cpu";
|
|
220
|
+
PerformanceMetricType["TOOL_EXECUTION"] = "tool_execution";
|
|
221
|
+
PerformanceMetricType["API_REQUEST"] = "api_request";
|
|
222
|
+
PerformanceMetricType["TOKEN_EFFICIENCY"] = "token_efficiency";
|
|
223
|
+
})(PerformanceMetricType || (PerformanceMetricType = {}));
|
|
224
|
+
export var MemoryMetricType;
|
|
225
|
+
(function (MemoryMetricType) {
|
|
226
|
+
MemoryMetricType["HEAP_USED"] = "heap_used";
|
|
227
|
+
MemoryMetricType["HEAP_TOTAL"] = "heap_total";
|
|
228
|
+
MemoryMetricType["EXTERNAL"] = "external";
|
|
229
|
+
MemoryMetricType["RSS"] = "rss";
|
|
230
|
+
})(MemoryMetricType || (MemoryMetricType = {}));
|
|
231
|
+
export var ToolExecutionPhase;
|
|
232
|
+
(function (ToolExecutionPhase) {
|
|
233
|
+
ToolExecutionPhase["VALIDATION"] = "validation";
|
|
234
|
+
ToolExecutionPhase["PREPARATION"] = "preparation";
|
|
235
|
+
ToolExecutionPhase["EXECUTION"] = "execution";
|
|
236
|
+
ToolExecutionPhase["RESULT_PROCESSING"] = "result_processing";
|
|
237
|
+
})(ToolExecutionPhase || (ToolExecutionPhase = {}));
|
|
238
|
+
export var ApiRequestPhase;
|
|
239
|
+
(function (ApiRequestPhase) {
|
|
240
|
+
ApiRequestPhase["REQUEST_PREPARATION"] = "request_preparation";
|
|
241
|
+
ApiRequestPhase["NETWORK_LATENCY"] = "network_latency";
|
|
242
|
+
ApiRequestPhase["RESPONSE_PROCESSING"] = "response_processing";
|
|
243
|
+
ApiRequestPhase["TOKEN_PROCESSING"] = "token_processing";
|
|
244
|
+
})(ApiRequestPhase || (ApiRequestPhase = {}));
|
|
14
245
|
let cliMeter;
|
|
15
246
|
let toolCallCounter;
|
|
16
247
|
let toolCallLatencyHistogram;
|
|
17
248
|
let apiRequestCounter;
|
|
18
249
|
let apiRequestLatencyHistogram;
|
|
19
250
|
let tokenUsageCounter;
|
|
251
|
+
let sessionCounter;
|
|
20
252
|
let fileOperationCounter;
|
|
21
253
|
let chatCompressionCounter;
|
|
22
254
|
let invalidChunkCounter;
|
|
@@ -24,12 +256,21 @@ let contentRetryCounter;
|
|
|
24
256
|
let contentRetryFailureCounter;
|
|
25
257
|
let modelRoutingLatencyHistogram;
|
|
26
258
|
let modelRoutingFailureCounter;
|
|
259
|
+
let modelSlashCommandCallCounter;
|
|
260
|
+
// Performance Monitoring Metrics
|
|
261
|
+
let startupTimeHistogram;
|
|
262
|
+
let memoryUsageGauge; // Using Histogram until ObservableGauge is available
|
|
263
|
+
let cpuUsageGauge;
|
|
264
|
+
let toolQueueDepthGauge;
|
|
265
|
+
let toolExecutionBreakdownHistogram;
|
|
266
|
+
let tokenEfficiencyHistogram;
|
|
267
|
+
let apiRequestBreakdownHistogram;
|
|
268
|
+
let performanceScoreGauge;
|
|
269
|
+
let regressionDetectionCounter;
|
|
270
|
+
let regressionPercentageChangeHistogram;
|
|
271
|
+
let baselineComparisonHistogram;
|
|
27
272
|
let isMetricsInitialized = false;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
'session.id': config.getSessionId(),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
273
|
+
let isPerformanceMonitoringEnabled = false;
|
|
33
274
|
export function getMeter() {
|
|
34
275
|
if (!cliMeter) {
|
|
35
276
|
cliMeter = metrics.getMeter(SERVICE_NAME);
|
|
@@ -42,148 +283,88 @@ export function initializeMetrics(config) {
|
|
|
42
283
|
const meter = getMeter();
|
|
43
284
|
if (!meter)
|
|
44
285
|
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,
|
|
53
|
-
});
|
|
54
|
-
apiRequestCounter = meter.createCounter(METRIC_API_REQUEST_COUNT, {
|
|
55
|
-
description: 'Counts API requests, tagged by model and status.',
|
|
56
|
-
valueType: ValueType.INT,
|
|
57
|
-
});
|
|
58
|
-
apiRequestLatencyHistogram = meter.createHistogram(METRIC_API_REQUEST_LATENCY, {
|
|
59
|
-
description: 'Latency of API requests in milliseconds.',
|
|
60
|
-
unit: 'ms',
|
|
61
|
-
valueType: ValueType.INT,
|
|
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,
|
|
286
|
+
// Initialize core metrics
|
|
287
|
+
Object.entries(COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
288
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
83
289
|
});
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
290
|
+
Object.entries(HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
291
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
96
292
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
sessionCounter.add(1, getCommonAttributes(config));
|
|
293
|
+
// Increment session counter after all metrics are initialized
|
|
294
|
+
sessionCounter?.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
295
|
+
// Initialize performance monitoring metrics if enabled
|
|
296
|
+
initializePerformanceMonitoring(config);
|
|
102
297
|
isMetricsInitialized = true;
|
|
103
298
|
}
|
|
104
|
-
export function recordChatCompressionMetrics(config,
|
|
299
|
+
export function recordChatCompressionMetrics(config, attributes) {
|
|
105
300
|
if (!chatCompressionCounter || !isMetricsInitialized)
|
|
106
301
|
return;
|
|
107
302
|
chatCompressionCounter.add(1, {
|
|
108
|
-
...getCommonAttributes(config),
|
|
109
|
-
...
|
|
303
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
304
|
+
...attributes,
|
|
110
305
|
});
|
|
111
306
|
}
|
|
112
|
-
export function recordToolCallMetrics(config,
|
|
307
|
+
export function recordToolCallMetrics(config, durationMs, attributes) {
|
|
113
308
|
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
|
|
114
309
|
return;
|
|
115
310
|
const metricAttributes = {
|
|
116
|
-
...getCommonAttributes(config),
|
|
117
|
-
|
|
118
|
-
success,
|
|
119
|
-
decision,
|
|
120
|
-
tool_type,
|
|
311
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
312
|
+
...attributes,
|
|
121
313
|
};
|
|
122
314
|
toolCallCounter.add(1, metricAttributes);
|
|
123
315
|
toolCallLatencyHistogram.record(durationMs, {
|
|
124
|
-
...getCommonAttributes(config),
|
|
125
|
-
function_name:
|
|
316
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
317
|
+
function_name: attributes.function_name,
|
|
126
318
|
});
|
|
127
319
|
}
|
|
128
|
-
export function recordTokenUsageMetrics(config,
|
|
320
|
+
export function recordTokenUsageMetrics(config, tokenCount, attributes) {
|
|
129
321
|
if (!tokenUsageCounter || !isMetricsInitialized)
|
|
130
322
|
return;
|
|
131
323
|
tokenUsageCounter.add(tokenCount, {
|
|
132
|
-
...getCommonAttributes(config),
|
|
133
|
-
|
|
134
|
-
type,
|
|
324
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
325
|
+
...attributes,
|
|
135
326
|
});
|
|
136
327
|
}
|
|
137
|
-
export function recordApiResponseMetrics(config,
|
|
328
|
+
export function recordApiResponseMetrics(config, durationMs, attributes) {
|
|
138
329
|
if (!apiRequestCounter ||
|
|
139
330
|
!apiRequestLatencyHistogram ||
|
|
140
331
|
!isMetricsInitialized)
|
|
141
332
|
return;
|
|
142
333
|
const metricAttributes = {
|
|
143
|
-
...getCommonAttributes(config),
|
|
144
|
-
model,
|
|
145
|
-
status_code:
|
|
334
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
335
|
+
model: attributes.model,
|
|
336
|
+
status_code: attributes.status_code ?? 'ok',
|
|
146
337
|
};
|
|
147
338
|
apiRequestCounter.add(1, metricAttributes);
|
|
148
339
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
149
|
-
...getCommonAttributes(config),
|
|
150
|
-
model,
|
|
340
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
341
|
+
model: attributes.model,
|
|
151
342
|
});
|
|
152
343
|
}
|
|
153
|
-
export function recordApiErrorMetrics(config,
|
|
344
|
+
export function recordApiErrorMetrics(config, durationMs, attributes) {
|
|
154
345
|
if (!apiRequestCounter ||
|
|
155
346
|
!apiRequestLatencyHistogram ||
|
|
156
347
|
!isMetricsInitialized)
|
|
157
348
|
return;
|
|
158
349
|
const metricAttributes = {
|
|
159
|
-
...getCommonAttributes(config),
|
|
160
|
-
model,
|
|
161
|
-
status_code:
|
|
162
|
-
error_type:
|
|
350
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
351
|
+
model: attributes.model,
|
|
352
|
+
status_code: attributes.status_code ?? 'error',
|
|
353
|
+
error_type: attributes.error_type ?? 'unknown',
|
|
163
354
|
};
|
|
164
355
|
apiRequestCounter.add(1, metricAttributes);
|
|
165
356
|
apiRequestLatencyHistogram.record(durationMs, {
|
|
166
|
-
...getCommonAttributes(config),
|
|
167
|
-
model,
|
|
357
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
358
|
+
model: attributes.model,
|
|
168
359
|
});
|
|
169
360
|
}
|
|
170
|
-
export function recordFileOperationMetric(config,
|
|
361
|
+
export function recordFileOperationMetric(config, attributes) {
|
|
171
362
|
if (!fileOperationCounter || !isMetricsInitialized)
|
|
172
363
|
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);
|
|
364
|
+
fileOperationCounter.add(1, {
|
|
365
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
366
|
+
...attributes,
|
|
367
|
+
});
|
|
187
368
|
}
|
|
188
369
|
// --- New Metric Recording Functions ---
|
|
189
370
|
/**
|
|
@@ -192,7 +373,7 @@ export function recordFileOperationMetric(config, operation, lines, mimetype, ex
|
|
|
192
373
|
export function recordInvalidChunk(config) {
|
|
193
374
|
if (!invalidChunkCounter || !isMetricsInitialized)
|
|
194
375
|
return;
|
|
195
|
-
invalidChunkCounter.add(1, getCommonAttributes(config));
|
|
376
|
+
invalidChunkCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
196
377
|
}
|
|
197
378
|
/**
|
|
198
379
|
* Records a metric for when a retry is triggered due to a content error.
|
|
@@ -200,7 +381,7 @@ export function recordInvalidChunk(config) {
|
|
|
200
381
|
export function recordContentRetry(config) {
|
|
201
382
|
if (!contentRetryCounter || !isMetricsInitialized)
|
|
202
383
|
return;
|
|
203
|
-
contentRetryCounter.add(1, getCommonAttributes(config));
|
|
384
|
+
contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
204
385
|
}
|
|
205
386
|
/**
|
|
206
387
|
* Records a metric for when all content error retries have failed for a request.
|
|
@@ -208,7 +389,15 @@ export function recordContentRetry(config) {
|
|
|
208
389
|
export function recordContentRetryFailure(config) {
|
|
209
390
|
if (!contentRetryFailureCounter || !isMetricsInitialized)
|
|
210
391
|
return;
|
|
211
|
-
contentRetryFailureCounter.add(1, getCommonAttributes(config));
|
|
392
|
+
contentRetryFailureCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
393
|
+
}
|
|
394
|
+
export function recordModelSlashCommand(config, event) {
|
|
395
|
+
if (!modelSlashCommandCallCounter || !isMetricsInitialized)
|
|
396
|
+
return;
|
|
397
|
+
modelSlashCommandCallCounter.add(1, {
|
|
398
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
399
|
+
'slash_command.model.model_name': event.model_name,
|
|
400
|
+
});
|
|
212
401
|
}
|
|
213
402
|
export function recordModelRoutingMetrics(config, event) {
|
|
214
403
|
if (!modelRoutingLatencyHistogram ||
|
|
@@ -216,16 +405,141 @@ export function recordModelRoutingMetrics(config, event) {
|
|
|
216
405
|
!isMetricsInitialized)
|
|
217
406
|
return;
|
|
218
407
|
modelRoutingLatencyHistogram.record(event.routing_latency_ms, {
|
|
219
|
-
...getCommonAttributes(config),
|
|
408
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
220
409
|
'routing.decision_model': event.decision_model,
|
|
221
410
|
'routing.decision_source': event.decision_source,
|
|
222
411
|
});
|
|
223
412
|
if (event.failed) {
|
|
224
413
|
modelRoutingFailureCounter.add(1, {
|
|
225
|
-
...getCommonAttributes(config),
|
|
414
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
226
415
|
'routing.decision_source': event.decision_source,
|
|
227
416
|
'routing.error_message': event.error_message,
|
|
228
417
|
});
|
|
229
418
|
}
|
|
230
419
|
}
|
|
420
|
+
// Performance Monitoring Functions
|
|
421
|
+
export function initializePerformanceMonitoring(config) {
|
|
422
|
+
const meter = getMeter();
|
|
423
|
+
if (!meter)
|
|
424
|
+
return;
|
|
425
|
+
// Check if performance monitoring is enabled in config
|
|
426
|
+
// For now, enable performance monitoring when telemetry is enabled
|
|
427
|
+
// TODO: Add specific performance monitoring settings to config
|
|
428
|
+
isPerformanceMonitoringEnabled = config.getTelemetryEnabled();
|
|
429
|
+
if (!isPerformanceMonitoringEnabled)
|
|
430
|
+
return;
|
|
431
|
+
Object.entries(PERFORMANCE_COUNTER_DEFINITIONS).forEach(([name, { description, valueType, assign }]) => {
|
|
432
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
433
|
+
});
|
|
434
|
+
Object.entries(PERFORMANCE_HISTOGRAM_DEFINITIONS).forEach(([name, { description, unit, valueType, assign }]) => {
|
|
435
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
export function recordStartupPerformance(config, durationMs, attributes) {
|
|
439
|
+
if (!startupTimeHistogram || !isPerformanceMonitoringEnabled)
|
|
440
|
+
return;
|
|
441
|
+
const metricAttributes = {
|
|
442
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
443
|
+
phase: attributes.phase,
|
|
444
|
+
...attributes.details,
|
|
445
|
+
};
|
|
446
|
+
startupTimeHistogram.record(durationMs, metricAttributes);
|
|
447
|
+
}
|
|
448
|
+
export function recordMemoryUsage(config, bytes, attributes) {
|
|
449
|
+
if (!memoryUsageGauge || !isPerformanceMonitoringEnabled)
|
|
450
|
+
return;
|
|
451
|
+
const metricAttributes = {
|
|
452
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
453
|
+
...attributes,
|
|
454
|
+
};
|
|
455
|
+
memoryUsageGauge.record(bytes, metricAttributes);
|
|
456
|
+
}
|
|
457
|
+
export function recordCpuUsage(config, percentage, attributes) {
|
|
458
|
+
if (!cpuUsageGauge || !isPerformanceMonitoringEnabled)
|
|
459
|
+
return;
|
|
460
|
+
const metricAttributes = {
|
|
461
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
462
|
+
...attributes,
|
|
463
|
+
};
|
|
464
|
+
cpuUsageGauge.record(percentage, metricAttributes);
|
|
465
|
+
}
|
|
466
|
+
export function recordToolQueueDepth(config, queueDepth) {
|
|
467
|
+
if (!toolQueueDepthGauge || !isPerformanceMonitoringEnabled)
|
|
468
|
+
return;
|
|
469
|
+
const attributes = {
|
|
470
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
471
|
+
};
|
|
472
|
+
toolQueueDepthGauge.record(queueDepth, attributes);
|
|
473
|
+
}
|
|
474
|
+
export function recordToolExecutionBreakdown(config, durationMs, attributes) {
|
|
475
|
+
if (!toolExecutionBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
476
|
+
return;
|
|
477
|
+
const metricAttributes = {
|
|
478
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
479
|
+
...attributes,
|
|
480
|
+
};
|
|
481
|
+
toolExecutionBreakdownHistogram.record(durationMs, metricAttributes);
|
|
482
|
+
}
|
|
483
|
+
export function recordTokenEfficiency(config, value, attributes) {
|
|
484
|
+
if (!tokenEfficiencyHistogram || !isPerformanceMonitoringEnabled)
|
|
485
|
+
return;
|
|
486
|
+
const metricAttributes = {
|
|
487
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
488
|
+
...attributes,
|
|
489
|
+
};
|
|
490
|
+
tokenEfficiencyHistogram.record(value, metricAttributes);
|
|
491
|
+
}
|
|
492
|
+
export function recordApiRequestBreakdown(config, durationMs, attributes) {
|
|
493
|
+
if (!apiRequestBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
494
|
+
return;
|
|
495
|
+
const metricAttributes = {
|
|
496
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
497
|
+
...attributes,
|
|
498
|
+
};
|
|
499
|
+
apiRequestBreakdownHistogram.record(durationMs, metricAttributes);
|
|
500
|
+
}
|
|
501
|
+
export function recordPerformanceScore(config, score, attributes) {
|
|
502
|
+
if (!performanceScoreGauge || !isPerformanceMonitoringEnabled)
|
|
503
|
+
return;
|
|
504
|
+
const metricAttributes = {
|
|
505
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
506
|
+
...attributes,
|
|
507
|
+
};
|
|
508
|
+
performanceScoreGauge.record(score, metricAttributes);
|
|
509
|
+
}
|
|
510
|
+
export function recordPerformanceRegression(config, attributes) {
|
|
511
|
+
if (!regressionDetectionCounter || !isPerformanceMonitoringEnabled)
|
|
512
|
+
return;
|
|
513
|
+
const metricAttributes = {
|
|
514
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
515
|
+
...attributes,
|
|
516
|
+
};
|
|
517
|
+
regressionDetectionCounter.add(1, metricAttributes);
|
|
518
|
+
if (attributes.baseline_value !== 0 && regressionPercentageChangeHistogram) {
|
|
519
|
+
const percentageChange = ((attributes.current_value - attributes.baseline_value) /
|
|
520
|
+
attributes.baseline_value) *
|
|
521
|
+
100;
|
|
522
|
+
regressionPercentageChangeHistogram.record(percentageChange, metricAttributes);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
export function recordBaselineComparison(config, attributes) {
|
|
526
|
+
if (!baselineComparisonHistogram || !isPerformanceMonitoringEnabled)
|
|
527
|
+
return;
|
|
528
|
+
if (attributes.baseline_value === 0) {
|
|
529
|
+
diag.warn('Baseline value is zero, skipping comparison.');
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const percentageChange = ((attributes.current_value - attributes.baseline_value) /
|
|
533
|
+
attributes.baseline_value) *
|
|
534
|
+
100;
|
|
535
|
+
const metricAttributes = {
|
|
536
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
537
|
+
...attributes,
|
|
538
|
+
};
|
|
539
|
+
baselineComparisonHistogram.record(percentageChange, metricAttributes);
|
|
540
|
+
}
|
|
541
|
+
// Utility function to check if performance monitoring is enabled
|
|
542
|
+
export function isPerformanceMonitoringActive() {
|
|
543
|
+
return isPerformanceMonitoringEnabled && isMetricsInitialized;
|
|
544
|
+
}
|
|
231
545
|
//# sourceMappingURL=metrics.js.map
|