Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ export class ClearcutLogger {
eventName: EventNames,
data: EventValue[] = [],
): LogEvent {
const email = this.userAccountManager.getCachedGoogleAccount();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The method getCachedGoogleAccount() performs a synchronous file read on every call. Since createBasicLogEvent is now called for every telemetry event, this synchronous I/O could block the Node.js event loop and cause performance issues, especially when many events are logged in quick succession. This could impact the application's responsiveness.

To mitigate this, consider caching the email within the ClearcutLogger instance. A more robust solution would be to add in-memory caching to the UserAccountManager itself to avoid repeated file reads across the application.

const surface = determineSurface();
const ghWorkflowName = determineGHWorkflowName();

const baseMetadata: EventValue[] = [
...data,
{
Expand Down Expand Up @@ -321,34 +323,32 @@ export class ClearcutLogger {
});
}

return {
const logEvent: LogEvent = {
console_type: 'GEMINI_CLI',
application: 102, // GEMINI_CLI
event_name: eventName as string,
event_metadata: [baseMetadata],
};

// Should log either email or install ID, not both. See go/cloudmill-1p-oss-instrumentation#define-sessionable-id
if (email) {
logEvent.client_email = email;
} else {
logEvent.client_install_id = this.installationManager.getInstallationId();
}

return logEvent;
}

createLogEvent(eventName: EventNames, data: EventValue[] = []): LogEvent {
const email = this.userAccountManager.getCachedGoogleAccount();

if (eventName !== EventNames.START_SESSION) {
data.push(...this.sessionData);
}
const totalAccounts = this.userAccountManager.getLifetimeGoogleAccounts();

data = this.addDefaultFields(data, totalAccounts);

const logEvent = this.createBasicLogEvent(eventName, data);

// Should log either email or install ID, not both. See go/cloudmill-1p-oss-instrumentation#define-sessionable-id
if (email) {
logEvent.client_email = email;
} else {
logEvent.client_install_id = this.installationManager.getInstallationId();
}

return logEvent;
return this.createBasicLogEvent(eventName, data);
}

flushIfNeeded(): void {
Expand Down