Stop logging session ids on extension events (#11941)

This commit is contained in:
owenofbrien
2025-10-24 10:11:42 -07:00
committed by GitHub
parent 978fbcf95e
commit 8bdef8754e
2 changed files with 40 additions and 30 deletions

View File

@@ -413,7 +413,7 @@ describe('ClearcutLogger', () => {
vi.stubEnv('CURSOR_TRACE_ID', '');
}
const event = logger?.createLogEvent(EventNames.API_ERROR, []);
expect(event?.event_metadata[0][3]).toEqual({
expect(event?.event_metadata[0]).toContainEqual({
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
value: expectedValue,
});

View File

@@ -250,6 +250,39 @@ export class ClearcutLogger {
}
}
createBasicLogEvent(
eventName: EventNames,
data: EventValue[] = [],
): LogEvent {
const surface = determineSurface();
return {
console_type: 'GEMINI_CLI',
application: 102, // GEMINI_CLI
event_name: eventName as string,
event_metadata: [
[
...data,
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
value: surface,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_VERSION,
value: CLI_VERSION,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_GIT_COMMIT_HASH,
value: GIT_COMMIT_INFO,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_OS,
value: process.platform,
},
],
],
};
}
createLogEvent(eventName: EventNames, data: EventValue[] = []): LogEvent {
const email = this.userAccountManager.getCachedGoogleAccount();
@@ -260,12 +293,7 @@ export class ClearcutLogger {
data = this.addDefaultFields(data, totalAccounts);
const logEvent: LogEvent = {
console_type: 'GEMINI_CLI',
application: 102, // GEMINI_CLI
event_name: eventName as string,
event_metadata: [data],
};
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) {
@@ -921,7 +949,7 @@ export class ClearcutLogger {
];
this.enqueueLogEvent(
this.createLogEvent(EventNames.EXTENSION_INSTALL, data),
this.createBasicLogEvent(EventNames.EXTENSION_INSTALL, data),
);
this.flushToClearcut().catch((error) => {
debugLogger.debug('Error flushing to Clearcut:', error);
@@ -945,7 +973,7 @@ export class ClearcutLogger {
];
this.enqueueLogEvent(
this.createLogEvent(EventNames.EXTENSION_UNINSTALL, data),
this.createBasicLogEvent(EventNames.EXTENSION_UNINSTALL, data),
);
this.flushToClearcut().catch((error) => {
debugLogger.debug('Error flushing to Clearcut:', error);
@@ -981,7 +1009,7 @@ export class ClearcutLogger {
];
this.enqueueLogEvent(
this.createLogEvent(EventNames.EXTENSION_UPDATE, data),
this.createBasicLogEvent(EventNames.EXTENSION_UPDATE, data),
);
this.flushToClearcut().catch((error) => {
debugLogger.debug('Error flushing to Clearcut:', error);
@@ -1070,7 +1098,7 @@ export class ClearcutLogger {
];
this.enqueueLogEvent(
this.createLogEvent(EventNames.EXTENSION_ENABLE, data),
this.createBasicLogEvent(EventNames.EXTENSION_ENABLE, data),
);
this.flushToClearcut().catch((error) => {
debugLogger.debug('Error flushing to Clearcut:', error);
@@ -1109,7 +1137,7 @@ export class ClearcutLogger {
];
this.enqueueLogEvent(
this.createLogEvent(EventNames.EXTENSION_DISABLE, data),
this.createBasicLogEvent(EventNames.EXTENSION_DISABLE, data),
);
this.flushToClearcut().catch((error) => {
debugLogger.debug('Error flushing to Clearcut:', error);
@@ -1207,8 +1235,6 @@ export class ClearcutLogger {
* should exist on all log events.
*/
addDefaultFields(data: EventValue[], totalAccounts: number): EventValue[] {
const surface = determineSurface();
const defaultLogMetadata: EventValue[] = [
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SESSION_ID,
@@ -1224,26 +1250,10 @@ export class ClearcutLogger {
gemini_cli_key: EventMetadataKey.GEMINI_CLI_GOOGLE_ACCOUNTS_COUNT,
value: `${totalAccounts}`,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
value: surface,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_VERSION,
value: CLI_VERSION,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_GIT_COMMIT_HASH,
value: GIT_COMMIT_INFO,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_PROMPT_ID,
value: this.promptId,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_OS,
value: process.platform,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_NODE_VERSION,
value: process.versions.node,