From 0a8e9410979551755bd1577eb40b9d4536f0b9f6 Mon Sep 17 00:00:00 2001 From: Arya Gummadi Date: Mon, 25 Aug 2025 14:20:17 -0700 Subject: [PATCH] fix(telemetry): Update logger tests to handle user email field (#7050) --- packages/core/src/telemetry/loggers.test.ts | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/core/src/telemetry/loggers.test.ts b/packages/core/src/telemetry/loggers.test.ts index 1221ac27..44df1045 100644 --- a/packages/core/src/telemetry/loggers.test.ts +++ b/packages/core/src/telemetry/loggers.test.ts @@ -56,6 +56,7 @@ import { GenerateContentResponseUsageMetadata } from '@google/genai'; import * as uiTelemetry from './uiTelemetry.js'; import { makeFakeConfig } from '../test-utils/config.js'; import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js'; +import { UserAccountManager } from '../utils/userAccountManager.js'; describe('loggers', () => { const mockLogger = { @@ -72,6 +73,10 @@ describe('loggers', () => { vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation( mockUiEvent.addEvent, ); + vi.spyOn( + UserAccountManager.prototype, + 'getCachedGoogleAccount', + ).mockReturnValue('test-user@example.com'); vi.useFakeTimers(); vi.setSystemTime(new Date('2025-01-01T00:00:00.000Z')); }); @@ -152,6 +157,7 @@ describe('loggers', () => { body: 'CLI configuration loaded.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_CLI_CONFIG, 'event.timestamp': '2025-01-01T00:00:00.000Z', model: 'test-model', @@ -195,6 +201,7 @@ describe('loggers', () => { body: 'User prompt. Length: 11.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_USER_PROMPT, 'event.timestamp': '2025-01-01T00:00:00.000Z', prompt_length: 11, @@ -223,6 +230,7 @@ describe('loggers', () => { body: 'User prompt. Length: 11.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_USER_PROMPT, 'event.timestamp': '2025-01-01T00:00:00.000Z', prompt_length: 11, @@ -277,6 +285,7 @@ describe('loggers', () => { body: 'API response from test-model. Status: 200. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_API_RESPONSE, 'event.timestamp': '2025-01-01T00:00:00.000Z', [SemanticAttributes.HTTP_STATUS_CODE]: 200, @@ -292,6 +301,7 @@ describe('loggers', () => { response_text: 'test-response', prompt_id: 'prompt-id-1', auth_type: 'oauth-personal', + error: undefined, }, }); @@ -341,6 +351,7 @@ describe('loggers', () => { body: 'API response from test-model. Status: 200. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', ...event, 'event.name': EVENT_API_RESPONSE, 'event.timestamp': '2025-01-01T00:00:00.000Z', @@ -378,6 +389,7 @@ describe('loggers', () => { body: 'API request to test-model.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_API_REQUEST, 'event.timestamp': '2025-01-01T00:00:00.000Z', model: 'test-model', @@ -396,6 +408,7 @@ describe('loggers', () => { body: 'API request to test-model.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_API_REQUEST, 'event.timestamp': '2025-01-01T00:00:00.000Z', model: 'test-model', @@ -420,6 +433,7 @@ describe('loggers', () => { body: 'Switching to flash as Fallback.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_FLASH_FALLBACK, 'event.timestamp': '2025-01-01T00:00:00.000Z', auth_type: 'vertex-ai', @@ -516,6 +530,7 @@ describe('loggers', () => { body: 'Tool call: test-function. Decision: accept. Success: true. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_TOOL_CALL, 'event.timestamp': '2025-01-01T00:00:00.000Z', function_name: 'test-function', @@ -532,6 +547,9 @@ describe('loggers', () => { decision: ToolCallDecision.ACCEPT, prompt_id: 'prompt-id-1', tool_type: 'native', + error: undefined, + error_type: undefined, + metadata: undefined, }, }); @@ -581,6 +599,7 @@ describe('loggers', () => { body: 'Tool call: test-function. Decision: reject. Success: false. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_TOOL_CALL, 'event.timestamp': '2025-01-01T00:00:00.000Z', function_name: 'test-function', @@ -597,6 +616,9 @@ describe('loggers', () => { decision: ToolCallDecision.REJECT, prompt_id: 'prompt-id-2', tool_type: 'native', + error: undefined, + error_type: undefined, + metadata: undefined, }, }); @@ -649,6 +671,7 @@ describe('loggers', () => { body: 'Tool call: test-function. Decision: modify. Success: true. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_TOOL_CALL, 'event.timestamp': '2025-01-01T00:00:00.000Z', function_name: 'test-function', @@ -665,6 +688,9 @@ describe('loggers', () => { decision: ToolCallDecision.MODIFY, prompt_id: 'prompt-id-3', tool_type: 'native', + error: undefined, + error_type: undefined, + metadata: undefined, }, }); @@ -716,6 +742,7 @@ describe('loggers', () => { body: 'Tool call: test-function. Success: true. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_TOOL_CALL, 'event.timestamp': '2025-01-01T00:00:00.000Z', function_name: 'test-function', @@ -731,6 +758,10 @@ describe('loggers', () => { success: true, prompt_id: 'prompt-id-4', tool_type: 'native', + decision: undefined, + error: undefined, + error_type: undefined, + metadata: undefined, }, }); @@ -783,6 +814,7 @@ describe('loggers', () => { body: 'Tool call: test-function. Success: false. Duration: 100ms.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_TOOL_CALL, 'event.timestamp': '2025-01-01T00:00:00.000Z', function_name: 'test-function', @@ -802,6 +834,8 @@ describe('loggers', () => { 'error.type': ToolErrorType.UNKNOWN, prompt_id: 'prompt-id-5', tool_type: 'native', + decision: undefined, + metadata: undefined, }, }); @@ -841,6 +875,7 @@ describe('loggers', () => { body: 'Malformed JSON response from test-model.', attributes: { 'session.id': 'test-session-id', + 'user.email': 'test-user@example.com', 'event.name': EVENT_MALFORMED_JSON_RESPONSE, 'event.timestamp': '2025-01-01T00:00:00.000Z', model: 'test-model',