mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
# 🚀 Sync Gemini CLI v0.2.1 - Major Feature Update (#483)
This commit is contained in:
@@ -21,6 +21,10 @@ import {
|
||||
METRIC_TOKEN_USAGE,
|
||||
METRIC_SESSION_COUNT,
|
||||
METRIC_FILE_OPERATION_COUNT,
|
||||
EVENT_CHAT_COMPRESSION,
|
||||
METRIC_INVALID_CHUNK_COUNT,
|
||||
METRIC_CONTENT_RETRY_COUNT,
|
||||
METRIC_CONTENT_RETRY_FAILURE_COUNT,
|
||||
} from './constants.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { DiffStat } from '../tools/tools.js';
|
||||
@@ -38,6 +42,10 @@ let apiRequestCounter: Counter | undefined;
|
||||
let apiRequestLatencyHistogram: Histogram | undefined;
|
||||
let tokenUsageCounter: Counter | undefined;
|
||||
let fileOperationCounter: Counter | undefined;
|
||||
let chatCompressionCounter: Counter | undefined;
|
||||
let invalidChunkCounter: Counter | undefined;
|
||||
let contentRetryCounter: Counter | undefined;
|
||||
let contentRetryFailureCounter: Counter | undefined;
|
||||
let isMetricsInitialized = false;
|
||||
|
||||
function getCommonAttributes(config: Config): Attributes {
|
||||
@@ -88,6 +96,28 @@ export function initializeMetrics(config: Config): void {
|
||||
description: 'Counts file operations (create, read, update).',
|
||||
valueType: ValueType.INT,
|
||||
});
|
||||
chatCompressionCounter = meter.createCounter(EVENT_CHAT_COMPRESSION, {
|
||||
description: 'Counts chat compression events.',
|
||||
valueType: ValueType.INT,
|
||||
});
|
||||
|
||||
// New counters for content errors
|
||||
invalidChunkCounter = meter.createCounter(METRIC_INVALID_CHUNK_COUNT, {
|
||||
description: 'Counts invalid chunks received from a stream.',
|
||||
valueType: ValueType.INT,
|
||||
});
|
||||
contentRetryCounter = meter.createCounter(METRIC_CONTENT_RETRY_COUNT, {
|
||||
description: 'Counts retries due to content errors (e.g., empty stream).',
|
||||
valueType: ValueType.INT,
|
||||
});
|
||||
contentRetryFailureCounter = meter.createCounter(
|
||||
METRIC_CONTENT_RETRY_FAILURE_COUNT,
|
||||
{
|
||||
description: 'Counts occurrences of all content retries failing.',
|
||||
valueType: ValueType.INT,
|
||||
},
|
||||
);
|
||||
|
||||
const sessionCounter = meter.createCounter(METRIC_SESSION_COUNT, {
|
||||
description: 'Count of CLI sessions started.',
|
||||
valueType: ValueType.INT,
|
||||
@@ -96,12 +126,24 @@ export function initializeMetrics(config: Config): void {
|
||||
isMetricsInitialized = true;
|
||||
}
|
||||
|
||||
export function recordChatCompressionMetrics(
|
||||
config: Config,
|
||||
args: { tokens_before: number; tokens_after: number },
|
||||
) {
|
||||
if (!chatCompressionCounter || !isMetricsInitialized) return;
|
||||
chatCompressionCounter.add(1, {
|
||||
...getCommonAttributes(config),
|
||||
...args,
|
||||
});
|
||||
}
|
||||
|
||||
export function recordToolCallMetrics(
|
||||
config: Config,
|
||||
functionName: string,
|
||||
durationMs: number,
|
||||
success: boolean,
|
||||
decision?: 'accept' | 'reject' | 'modify' | 'auto_accept',
|
||||
tool_type?: 'native' | 'mcp',
|
||||
): void {
|
||||
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
|
||||
return;
|
||||
@@ -111,6 +153,7 @@ export function recordToolCallMetrics(
|
||||
function_name: functionName,
|
||||
success,
|
||||
decision,
|
||||
tool_type,
|
||||
};
|
||||
toolCallCounter.add(1, metricAttributes);
|
||||
toolCallLatencyHistogram.record(durationMs, {
|
||||
@@ -197,14 +240,40 @@ export function recordFileOperationMetric(
|
||||
...getCommonAttributes(config),
|
||||
operation,
|
||||
};
|
||||
if (lines !== undefined) attributes.lines = lines;
|
||||
if (mimetype !== undefined) attributes.mimetype = mimetype;
|
||||
if (extension !== undefined) attributes.extension = extension;
|
||||
if (lines !== undefined) attributes['lines'] = lines;
|
||||
if (mimetype !== undefined) attributes['mimetype'] = mimetype;
|
||||
if (extension !== undefined) attributes['extension'] = extension;
|
||||
if (diffStat !== undefined) {
|
||||
attributes.ai_added_lines = diffStat.ai_added_lines;
|
||||
attributes.ai_removed_lines = diffStat.ai_removed_lines;
|
||||
attributes.user_added_lines = diffStat.user_added_lines;
|
||||
attributes.user_removed_lines = diffStat.user_removed_lines;
|
||||
attributes['ai_added_lines'] = diffStat.ai_added_lines;
|
||||
attributes['ai_removed_lines'] = diffStat.ai_removed_lines;
|
||||
attributes['user_added_lines'] = diffStat.user_added_lines;
|
||||
attributes['user_removed_lines'] = diffStat.user_removed_lines;
|
||||
}
|
||||
fileOperationCounter.add(1, attributes);
|
||||
}
|
||||
|
||||
// --- New Metric Recording Functions ---
|
||||
|
||||
/**
|
||||
* Records a metric for when an invalid chunk is received from a stream.
|
||||
*/
|
||||
export function recordInvalidChunk(config: Config): void {
|
||||
if (!invalidChunkCounter || !isMetricsInitialized) return;
|
||||
invalidChunkCounter.add(1, getCommonAttributes(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a metric for when a retry is triggered due to a content error.
|
||||
*/
|
||||
export function recordContentRetry(config: Config): void {
|
||||
if (!contentRetryCounter || !isMetricsInitialized) return;
|
||||
contentRetryCounter.add(1, getCommonAttributes(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a metric for when all content error retries have failed for a request.
|
||||
*/
|
||||
export function recordContentRetryFailure(config: Config): void {
|
||||
if (!contentRetryFailureCounter || !isMetricsInitialized) return;
|
||||
contentRetryFailureCounter.add(1, getCommonAttributes(config));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user