Update comment and undo unnecessary logging (#13025)

This commit is contained in:
Tommaso Sciortino
2025-11-13 19:11:13 -08:00
committed by GitHub
parent ab11b2c27f
commit 2c5e09e1c3
4 changed files with 20 additions and 71 deletions
+9
View File
@@ -575,6 +575,15 @@ export class GeminiChat {
content: responseText, content: responseText,
}); });
} }
// Stream validation logic: A stream is considered successful if:
// 1. There's a tool call OR
// 2. A not MALFORMED_FUNCTION_CALL finish reason and a non-mepty resp
//
// We throw an error only when there's no tool call AND:
// - No finish reason, OR
// - MALFORMED_FUNCTION_CALL finish reason OR
// - Empty response text (e.g., only thoughts with no actual content)
if (!hasToolCall) { if (!hasToolCall) {
if (!finishReason) { if (!finishReason) {
throw new InvalidStreamError( throw new InvalidStreamError(
+2 -2
View File
@@ -442,7 +442,7 @@ export function logContentRetry(
attributes: event.toOpenTelemetryAttributes(config), attributes: event.toOpenTelemetryAttributes(config),
}; };
logger.emit(logRecord); logger.emit(logRecord);
recordContentRetry(config, event.error_type); recordContentRetry(config);
} }
export function logContentRetryFailure( export function logContentRetryFailure(
@@ -458,7 +458,7 @@ export function logContentRetryFailure(
attributes: event.toOpenTelemetryAttributes(config), attributes: event.toOpenTelemetryAttributes(config),
}; };
logger.emit(logRecord); logger.emit(logRecord);
recordContentRetryFailure(config, event.final_error_type); recordContentRetryFailure(config);
} }
export function logModelRouting( export function logModelRouting(
@@ -96,8 +96,6 @@ describe('Telemetry Metrics', () => {
let recordAgentRunMetricsModule: typeof import('./metrics.js').recordAgentRunMetrics; let recordAgentRunMetricsModule: typeof import('./metrics.js').recordAgentRunMetrics;
let recordLinesChangedModule: typeof import('./metrics.js').recordLinesChanged; let recordLinesChangedModule: typeof import('./metrics.js').recordLinesChanged;
let recordSlowRenderModule: typeof import('./metrics.js').recordSlowRender; let recordSlowRenderModule: typeof import('./metrics.js').recordSlowRender;
let recordContentRetryModule: typeof import('./metrics.js').recordContentRetry;
let recordContentRetryFailureModule: typeof import('./metrics.js').recordContentRetryFailure;
beforeEach(async () => { beforeEach(async () => {
vi.resetModules(); vi.resetModules();
@@ -142,8 +140,6 @@ describe('Telemetry Metrics', () => {
recordAgentRunMetricsModule = metricsJsModule.recordAgentRunMetrics; recordAgentRunMetricsModule = metricsJsModule.recordAgentRunMetrics;
recordLinesChangedModule = metricsJsModule.recordLinesChanged; recordLinesChangedModule = metricsJsModule.recordLinesChanged;
recordSlowRenderModule = metricsJsModule.recordSlowRender; recordSlowRenderModule = metricsJsModule.recordSlowRender;
recordContentRetryModule = metricsJsModule.recordContentRetry;
recordContentRetryFailureModule = metricsJsModule.recordContentRetryFailure;
const otelApiModule = await import('@opentelemetry/api'); const otelApiModule = await import('@opentelemetry/api');
@@ -1347,50 +1343,4 @@ describe('Telemetry Metrics', () => {
}); });
}); });
}); });
describe('recordContentRetry', () => {
it('does not record metrics if not initialized', () => {
const config = makeFakeConfig({});
recordContentRetryModule(config, 'NO_FINISH_REASON');
expect(mockCounterAddFn).not.toHaveBeenCalled();
});
it('records a content retry event with error type when initialized', () => {
const config = makeFakeConfig({});
initializeMetricsModule(config);
mockCounterAddFn.mockClear(); // Clear the session start call
recordContentRetryModule(config, 'MALFORMED_FUNCTION_CALL');
expect(mockCounterAddFn).toHaveBeenCalledWith(1, {
'session.id': 'test-session-id',
'installation.id': 'test-installation-id',
'user.email': 'test@example.com',
error_type: 'MALFORMED_FUNCTION_CALL',
});
});
});
describe('recordContentRetryFailure', () => {
it('does not record metrics if not initialized', () => {
const config = makeFakeConfig({});
recordContentRetryFailureModule(config, 'NO_RESPONSE_TEXT');
expect(mockCounterAddFn).not.toHaveBeenCalled();
});
it('records a content retry failure event with error type when initialized', () => {
const config = makeFakeConfig({});
initializeMetricsModule(config);
mockCounterAddFn.mockClear(); // Clear the session start call
recordContentRetryFailureModule(config, 'MALFORMED_FUNCTION_CALL');
expect(mockCounterAddFn).toHaveBeenCalledWith(1, {
'session.id': 'test-session-id',
'installation.id': 'test-installation-id',
'user.email': 'test@example.com',
error_type: 'MALFORMED_FUNCTION_CALL',
});
});
});
}); });
+9 -19
View File
@@ -136,17 +136,13 @@ const COUNTER_DEFINITIONS = {
description: 'Counts retries due to content errors (e.g., empty stream).', description: 'Counts retries due to content errors (e.g., empty stream).',
valueType: ValueType.INT, valueType: ValueType.INT,
assign: (c: Counter) => (contentRetryCounter = c), assign: (c: Counter) => (contentRetryCounter = c),
attributes: {} as { attributes: {} as Record<string, never>,
error_type: string;
},
}, },
[CONTENT_RETRY_FAILURE_COUNT]: { [CONTENT_RETRY_FAILURE_COUNT]: {
description: 'Counts occurrences of all content retries failing.', description: 'Counts occurrences of all content retries failing.',
valueType: ValueType.INT, valueType: ValueType.INT,
assign: (c: Counter) => (contentRetryFailureCounter = c), assign: (c: Counter) => (contentRetryFailureCounter = c),
attributes: {} as { attributes: {} as Record<string, never>,
error_type: string;
},
}, },
[MODEL_ROUTING_FAILURE_COUNT]: { [MODEL_ROUTING_FAILURE_COUNT]: {
description: 'Counts model routing failures.', description: 'Counts model routing failures.',
@@ -719,26 +715,20 @@ export function recordInvalidChunk(config: Config): void {
/** /**
* Records a metric for when a retry is triggered due to a content error. * Records a metric for when a retry is triggered due to a content error.
*/ */
export function recordContentRetry(config: Config, errorType: string): void { export function recordContentRetry(config: Config): void {
if (!contentRetryCounter || !isMetricsInitialized) return; if (!contentRetryCounter || !isMetricsInitialized) return;
contentRetryCounter.add(1, { contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
...baseMetricDefinition.getCommonAttributes(config),
error_type: errorType,
});
} }
/** /**
* Records a metric for when all content error retries have failed for a request. * Records a metric for when all content error retries have failed for a request.
*/ */
export function recordContentRetryFailure( export function recordContentRetryFailure(config: Config): void {
config: Config,
errorType: string,
): void {
if (!contentRetryFailureCounter || !isMetricsInitialized) return; if (!contentRetryFailureCounter || !isMetricsInitialized) return;
contentRetryFailureCounter.add(1, { contentRetryFailureCounter.add(
...baseMetricDefinition.getCommonAttributes(config), 1,
error_type: errorType, baseMetricDefinition.getCommonAttributes(config),
}); );
} }
export function recordModelSlashCommand( export function recordModelSlashCommand(