Changes to add MCP tool count, and MCP tool name as dimension (#6631)

Co-authored-by: Ravikant Agarwal <ravikantag@google.com>
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
agarwalravikant 2025-08-20 19:52:22 +05:30 committed by GitHub
parent a773d0887c
commit 6b843ca3a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 51 additions and 5 deletions

View File

@ -488,11 +488,12 @@ describe('Server Config (config.ts)', () => {
},
);
it('logs the session start event', () => {
new Config({
it('logs the session start event', async () => {
const config = new Config({
...baseParams,
usageStatisticsEnabled: true,
});
await config.initialize();
expect(
ClearcutLogger.prototype.logStartSessionEvent,

View File

@ -346,8 +346,6 @@ export class Config {
if (this.telemetrySettings.enabled) {
initializeTelemetry(this);
}
logCliConfiguration(this, new StartSessionEvent(this));
}
/**
@ -365,6 +363,7 @@ export class Config {
}
this.promptRegistry = new PromptRegistry();
this.toolRegistry = await this.createToolRegistry();
logCliConfiguration(this, new StartSessionEvent(this, this.toolRegistry));
}
async refreshAuth(authMethod: AuthType) {

View File

@ -382,6 +382,20 @@ export class ClearcutLogger {
EventMetadataKey.GEMINI_CLI_START_SESSION_TELEMETRY_LOG_USER_PROMPTS_ENABLED,
value: event.telemetry_log_user_prompts_enabled.toString(),
},
{
gemini_cli_key:
EventMetadataKey.GEMINI_CLI_START_SESSION_MCP_SERVERS_COUNT,
value: event.mcp_servers_count ? event.mcp_servers_count : '',
},
{
gemini_cli_key:
EventMetadataKey.GEMINI_CLI_START_SESSION_MCP_TOOLS_COUNT,
value: event.mcp_tools_count ? event.mcp_tools_count : '',
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_START_SESSION_MCP_TOOLS,
value: event.mcp_tools ? event.mcp_tools : '',
},
];
this.sessionData = data;

View File

@ -237,4 +237,13 @@ export enum EventMetadataKey {
// Logs tool type whether it is mcp or native.
GEMINI_CLI_TOOL_TYPE = 62,
// Logs count of MCP servers in Start Session Event
GEMINI_CLI_START_SESSION_MCP_SERVERS_COUNT = 63,
// Logs count of MCP tools in Start Session Event
GEMINI_CLI_START_SESSION_MCP_TOOLS_COUNT = 64,
// Logs name of MCP tools as comma seperated string
GEMINI_CLI_START_SESSION_MCP_TOOLS = 65,
}

View File

@ -63,6 +63,7 @@ describe('loggers', () => {
};
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(sdk, 'isTelemetrySdkInitialized').mockReturnValue(true);
vi.spyOn(logs, 'getLogger').mockReturnValue(mockLogger);
vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation(
@ -161,6 +162,9 @@ describe('loggers', () => {
file_filtering_respect_git_ignore: true,
debug_mode: true,
mcp_servers: 'test-server',
mcp_servers_count: '1',
mcp_tools: undefined,
mcp_tools_count: undefined,
},
});
});

View File

@ -79,6 +79,9 @@ export function logCliConfiguration(
file_filtering_respect_git_ignore: event.file_filtering_respect_git_ignore,
debug_mode: event.debug_enabled,
mcp_servers: event.mcp_servers,
mcp_servers_count: event.mcp_servers_count,
mcp_tools: event.mcp_tools,
mcp_tools_count: event.mcp_tools_count,
};
const logger = logs.getLogger(SERVICE_NAME);

View File

@ -14,6 +14,7 @@ import {
getDecisionFromOutcome,
ToolCallDecision,
} from './tool-call-decision.js';
import { ToolRegistry } from '../tools/tool-registry.js';
export interface BaseTelemetryEvent {
'event.name': string;
@ -38,8 +39,11 @@ export class StartSessionEvent implements BaseTelemetryEvent {
telemetry_enabled: boolean;
telemetry_log_user_prompts_enabled: boolean;
file_filtering_respect_git_ignore: boolean;
mcp_servers_count?: string;
mcp_tools_count?: string;
mcp_tools?: string;
constructor(config: Config) {
constructor(config: Config, toolRegistry?: ToolRegistry) {
const generatorConfig = config.getContentGeneratorConfig();
const mcpServers = config.getMcpServers();
@ -66,6 +70,18 @@ export class StartSessionEvent implements BaseTelemetryEvent {
config.getTelemetryLogPromptsEnabled();
this.file_filtering_respect_git_ignore =
config.getFileFilteringRespectGitIgnore();
this.mcp_servers_count = mcpServers
? Object.keys(mcpServers).length.toString()
: '';
if (toolRegistry) {
const mcpTools = toolRegistry
.getAllTools()
.filter((tool) => tool instanceof DiscoveredMCPTool);
this.mcp_tools_count = mcpTools.length.toString();
this.mcp_tools = mcpTools
.map((tool) => (tool as DiscoveredMCPTool).name)
.join(',');
}
}
}