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:
parent
a773d0887c
commit
6b843ca3a8
|
@ -488,11 +488,12 @@ describe('Server Config (config.ts)', () => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it('logs the session start event', () => {
|
it('logs the session start event', async () => {
|
||||||
new Config({
|
const config = new Config({
|
||||||
...baseParams,
|
...baseParams,
|
||||||
usageStatisticsEnabled: true,
|
usageStatisticsEnabled: true,
|
||||||
});
|
});
|
||||||
|
await config.initialize();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
ClearcutLogger.prototype.logStartSessionEvent,
|
ClearcutLogger.prototype.logStartSessionEvent,
|
||||||
|
|
|
@ -346,8 +346,6 @@ export class Config {
|
||||||
if (this.telemetrySettings.enabled) {
|
if (this.telemetrySettings.enabled) {
|
||||||
initializeTelemetry(this);
|
initializeTelemetry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
logCliConfiguration(this, new StartSessionEvent(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -365,6 +363,7 @@ export class Config {
|
||||||
}
|
}
|
||||||
this.promptRegistry = new PromptRegistry();
|
this.promptRegistry = new PromptRegistry();
|
||||||
this.toolRegistry = await this.createToolRegistry();
|
this.toolRegistry = await this.createToolRegistry();
|
||||||
|
logCliConfiguration(this, new StartSessionEvent(this, this.toolRegistry));
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshAuth(authMethod: AuthType) {
|
async refreshAuth(authMethod: AuthType) {
|
||||||
|
|
|
@ -382,6 +382,20 @@ export class ClearcutLogger {
|
||||||
EventMetadataKey.GEMINI_CLI_START_SESSION_TELEMETRY_LOG_USER_PROMPTS_ENABLED,
|
EventMetadataKey.GEMINI_CLI_START_SESSION_TELEMETRY_LOG_USER_PROMPTS_ENABLED,
|
||||||
value: event.telemetry_log_user_prompts_enabled.toString(),
|
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;
|
this.sessionData = data;
|
||||||
|
|
||||||
|
|
|
@ -237,4 +237,13 @@ export enum EventMetadataKey {
|
||||||
|
|
||||||
// Logs tool type whether it is mcp or native.
|
// Logs tool type whether it is mcp or native.
|
||||||
GEMINI_CLI_TOOL_TYPE = 62,
|
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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ describe('loggers', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
vi.spyOn(sdk, 'isTelemetrySdkInitialized').mockReturnValue(true);
|
vi.spyOn(sdk, 'isTelemetrySdkInitialized').mockReturnValue(true);
|
||||||
vi.spyOn(logs, 'getLogger').mockReturnValue(mockLogger);
|
vi.spyOn(logs, 'getLogger').mockReturnValue(mockLogger);
|
||||||
vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation(
|
vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation(
|
||||||
|
@ -161,6 +162,9 @@ describe('loggers', () => {
|
||||||
file_filtering_respect_git_ignore: true,
|
file_filtering_respect_git_ignore: true,
|
||||||
debug_mode: true,
|
debug_mode: true,
|
||||||
mcp_servers: 'test-server',
|
mcp_servers: 'test-server',
|
||||||
|
mcp_servers_count: '1',
|
||||||
|
mcp_tools: undefined,
|
||||||
|
mcp_tools_count: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -79,6 +79,9 @@ export function logCliConfiguration(
|
||||||
file_filtering_respect_git_ignore: event.file_filtering_respect_git_ignore,
|
file_filtering_respect_git_ignore: event.file_filtering_respect_git_ignore,
|
||||||
debug_mode: event.debug_enabled,
|
debug_mode: event.debug_enabled,
|
||||||
mcp_servers: event.mcp_servers,
|
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);
|
const logger = logs.getLogger(SERVICE_NAME);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
getDecisionFromOutcome,
|
getDecisionFromOutcome,
|
||||||
ToolCallDecision,
|
ToolCallDecision,
|
||||||
} from './tool-call-decision.js';
|
} from './tool-call-decision.js';
|
||||||
|
import { ToolRegistry } from '../tools/tool-registry.js';
|
||||||
|
|
||||||
export interface BaseTelemetryEvent {
|
export interface BaseTelemetryEvent {
|
||||||
'event.name': string;
|
'event.name': string;
|
||||||
|
@ -38,8 +39,11 @@ export class StartSessionEvent implements BaseTelemetryEvent {
|
||||||
telemetry_enabled: boolean;
|
telemetry_enabled: boolean;
|
||||||
telemetry_log_user_prompts_enabled: boolean;
|
telemetry_log_user_prompts_enabled: boolean;
|
||||||
file_filtering_respect_git_ignore: 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 generatorConfig = config.getContentGeneratorConfig();
|
||||||
const mcpServers = config.getMcpServers();
|
const mcpServers = config.getMcpServers();
|
||||||
|
|
||||||
|
@ -66,6 +70,18 @@ export class StartSessionEvent implements BaseTelemetryEvent {
|
||||||
config.getTelemetryLogPromptsEnabled();
|
config.getTelemetryLogPromptsEnabled();
|
||||||
this.file_filtering_respect_git_ignore =
|
this.file_filtering_respect_git_ignore =
|
||||||
config.getFileFilteringRespectGitIgnore();
|
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(',');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue