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