add(telemetry): Add missing telemetry for UserPromptEvent (#6885)

Co-authored-by: Shnatu <snatu@google.com>
Co-authored-by: Arya Gummadi <aryagummadi@google.com>
This commit is contained in:
Shardul Natu
2025-08-27 19:17:32 -07:00
committed by GitHub
parent f22263c9e8
commit 539a49bd24
3 changed files with 15 additions and 4 deletions

View File

@@ -208,6 +208,8 @@ describe('loggers', () => {
'event.timestamp': '2025-01-01T00:00:00.000Z',
prompt_length: 11,
prompt: 'test-prompt',
prompt_id: 'prompt-id-8',
auth_type: 'vertex-ai',
},
});
});
@@ -222,8 +224,9 @@ describe('loggers', () => {
} as unknown as Config;
const event = new UserPromptEvent(
11,
'test-prompt',
'prompt-id-9',
AuthType.CLOUD_SHELL,
'test-prompt',
);
logUserPrompt(mockConfig, event);
@@ -236,6 +239,8 @@ describe('loggers', () => {
'event.name': EVENT_USER_PROMPT,
'event.timestamp': '2025-01-01T00:00:00.000Z',
prompt_length: 11,
prompt_id: 'prompt-id-9',
auth_type: 'cloud-shell',
},
});
});

View File

@@ -122,8 +122,13 @@ export function logUserPrompt(config: Config, event: UserPromptEvent): void {
'event.name': EVENT_USER_PROMPT,
'event.timestamp': new Date().toISOString(),
prompt_length: event.prompt_length,
prompt_id: event.prompt_id,
};
if (event.auth_type) {
attributes['auth_type'] = event.auth_type;
}
if (shouldLogUserPrompts(config)) {
attributes['prompt'] = event.prompt;
}