Changes to add tool_type as dimension (#6538)

Co-authored-by: Ravikant Agarwal <ravikantag@google.com>
This commit is contained in:
agarwalravikant
2025-08-19 10:55:47 +05:30
committed by GitHub
parent e290a61a52
commit 58c2925624
9 changed files with 46 additions and 0 deletions

View File

@@ -450,6 +450,10 @@ export class ClearcutLogger {
gemini_cli_key: EventMetadataKey.GEMINI_CLI_TOOL_CALL_ERROR_TYPE,
value: JSON.stringify(event.error_type),
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_TOOL_TYPE,
value: JSON.stringify(event.tool_type),
},
];
if (event.metadata) {

View File

@@ -234,4 +234,7 @@ export enum EventMetadataKey {
// Logs the number of tokens after context window compression.
GEMINI_CLI_COMPRESSION_TOKENS_AFTER = 61,
// Logs tool type whether it is mcp or native.
GEMINI_CLI_TOOL_TYPE = 62,
}

View File

@@ -524,6 +524,7 @@ describe('loggers', () => {
success: true,
decision: ToolCallDecision.ACCEPT,
prompt_id: 'prompt-id-1',
tool_type: 'native',
},
});
@@ -533,6 +534,7 @@ describe('loggers', () => {
100,
true,
ToolCallDecision.ACCEPT,
'native',
);
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({
@@ -587,6 +589,7 @@ describe('loggers', () => {
success: false,
decision: ToolCallDecision.REJECT,
prompt_id: 'prompt-id-2',
tool_type: 'native',
},
});
@@ -596,6 +599,7 @@ describe('loggers', () => {
100,
false,
ToolCallDecision.REJECT,
'native',
);
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({
@@ -653,6 +657,7 @@ describe('loggers', () => {
success: true,
decision: ToolCallDecision.MODIFY,
prompt_id: 'prompt-id-3',
tool_type: 'native',
},
});
@@ -662,6 +667,7 @@ describe('loggers', () => {
100,
true,
ToolCallDecision.MODIFY,
'native',
);
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({
@@ -717,6 +723,7 @@ describe('loggers', () => {
duration_ms: 100,
success: true,
prompt_id: 'prompt-id-4',
tool_type: 'native',
},
});
@@ -726,6 +733,7 @@ describe('loggers', () => {
100,
true,
undefined,
'native',
);
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({
@@ -786,6 +794,7 @@ describe('loggers', () => {
error_type: ToolErrorType.UNKNOWN,
'error.type': ToolErrorType.UNKNOWN,
prompt_id: 'prompt-id-5',
tool_type: 'native',
},
});
@@ -795,6 +804,7 @@ describe('loggers', () => {
100,
false,
undefined,
'native',
);
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({

View File

@@ -148,6 +148,7 @@ export function logToolCall(config: Config, event: ToolCallEvent): void {
event.duration_ms,
event.success,
event.decision,
event.tool_type,
);
}

View File

@@ -119,6 +119,7 @@ export function recordToolCallMetrics(
durationMs: number,
success: boolean,
decision?: 'accept' | 'reject' | 'modify' | 'auto_accept',
tool_type?: 'native' | 'mcp',
): void {
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
return;
@@ -128,6 +129,7 @@ export function recordToolCallMetrics(
function_name: functionName,
success,
decision,
tool_type,
};
toolCallCounter.add(1, metricAttributes);
toolCallLatencyHistogram.record(durationMs, {

View File

@@ -7,6 +7,7 @@
import { GenerateContentResponseUsageMetadata } from '@google/genai';
import { Config } from '../config/config.js';
import { CompletedToolCall } from '../core/coreToolScheduler.js';
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
import { FileDiff } from '../tools/tools.js';
import { AuthType } from '../core/contentGenerator.js';
import {
@@ -114,6 +115,7 @@ export class ToolCallEvent implements BaseTelemetryEvent {
error?: string;
error_type?: string;
prompt_id: string;
tool_type: 'native' | 'mcp';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata?: { [key: string]: any };
@@ -130,6 +132,10 @@ export class ToolCallEvent implements BaseTelemetryEvent {
this.error = call.response.error?.message;
this.error_type = call.response.errorType;
this.prompt_id = call.request.prompt_id;
this.tool_type =
typeof call.tool !== 'undefined' && call.tool instanceof DiscoveredMCPTool
? 'mcp'
: 'native';
if (
call.status === 'success' &&