mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix(telemetry): Update logger tests to handle user email field (#7050)
This commit is contained in:
@@ -56,6 +56,7 @@ import { GenerateContentResponseUsageMetadata } from '@google/genai';
|
|||||||
import * as uiTelemetry from './uiTelemetry.js';
|
import * as uiTelemetry from './uiTelemetry.js';
|
||||||
import { makeFakeConfig } from '../test-utils/config.js';
|
import { makeFakeConfig } from '../test-utils/config.js';
|
||||||
import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js';
|
import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js';
|
||||||
|
import { UserAccountManager } from '../utils/userAccountManager.js';
|
||||||
|
|
||||||
describe('loggers', () => {
|
describe('loggers', () => {
|
||||||
const mockLogger = {
|
const mockLogger = {
|
||||||
@@ -72,6 +73,10 @@ describe('loggers', () => {
|
|||||||
vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation(
|
vi.spyOn(uiTelemetry.uiTelemetryService, 'addEvent').mockImplementation(
|
||||||
mockUiEvent.addEvent,
|
mockUiEvent.addEvent,
|
||||||
);
|
);
|
||||||
|
vi.spyOn(
|
||||||
|
UserAccountManager.prototype,
|
||||||
|
'getCachedGoogleAccount',
|
||||||
|
).mockReturnValue('test-user@example.com');
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
vi.setSystemTime(new Date('2025-01-01T00:00:00.000Z'));
|
vi.setSystemTime(new Date('2025-01-01T00:00:00.000Z'));
|
||||||
});
|
});
|
||||||
@@ -152,6 +157,7 @@ describe('loggers', () => {
|
|||||||
body: 'CLI configuration loaded.',
|
body: 'CLI configuration loaded.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_CLI_CONFIG,
|
'event.name': EVENT_CLI_CONFIG,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
model: 'test-model',
|
model: 'test-model',
|
||||||
@@ -195,6 +201,7 @@ describe('loggers', () => {
|
|||||||
body: 'User prompt. Length: 11.',
|
body: 'User prompt. Length: 11.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_USER_PROMPT,
|
'event.name': EVENT_USER_PROMPT,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
prompt_length: 11,
|
prompt_length: 11,
|
||||||
@@ -223,6 +230,7 @@ describe('loggers', () => {
|
|||||||
body: 'User prompt. Length: 11.',
|
body: 'User prompt. Length: 11.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_USER_PROMPT,
|
'event.name': EVENT_USER_PROMPT,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
prompt_length: 11,
|
prompt_length: 11,
|
||||||
@@ -277,6 +285,7 @@ describe('loggers', () => {
|
|||||||
body: 'API response from test-model. Status: 200. Duration: 100ms.',
|
body: 'API response from test-model. Status: 200. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_API_RESPONSE,
|
'event.name': EVENT_API_RESPONSE,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
[SemanticAttributes.HTTP_STATUS_CODE]: 200,
|
[SemanticAttributes.HTTP_STATUS_CODE]: 200,
|
||||||
@@ -292,6 +301,7 @@ describe('loggers', () => {
|
|||||||
response_text: 'test-response',
|
response_text: 'test-response',
|
||||||
prompt_id: 'prompt-id-1',
|
prompt_id: 'prompt-id-1',
|
||||||
auth_type: 'oauth-personal',
|
auth_type: 'oauth-personal',
|
||||||
|
error: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -341,6 +351,7 @@ describe('loggers', () => {
|
|||||||
body: 'API response from test-model. Status: 200. Duration: 100ms.',
|
body: 'API response from test-model. Status: 200. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
...event,
|
...event,
|
||||||
'event.name': EVENT_API_RESPONSE,
|
'event.name': EVENT_API_RESPONSE,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
@@ -378,6 +389,7 @@ describe('loggers', () => {
|
|||||||
body: 'API request to test-model.',
|
body: 'API request to test-model.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_API_REQUEST,
|
'event.name': EVENT_API_REQUEST,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
model: 'test-model',
|
model: 'test-model',
|
||||||
@@ -396,6 +408,7 @@ describe('loggers', () => {
|
|||||||
body: 'API request to test-model.',
|
body: 'API request to test-model.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_API_REQUEST,
|
'event.name': EVENT_API_REQUEST,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
model: 'test-model',
|
model: 'test-model',
|
||||||
@@ -420,6 +433,7 @@ describe('loggers', () => {
|
|||||||
body: 'Switching to flash as Fallback.',
|
body: 'Switching to flash as Fallback.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_FLASH_FALLBACK,
|
'event.name': EVENT_FLASH_FALLBACK,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
auth_type: 'vertex-ai',
|
auth_type: 'vertex-ai',
|
||||||
@@ -516,6 +530,7 @@ describe('loggers', () => {
|
|||||||
body: 'Tool call: test-function. Decision: accept. Success: true. Duration: 100ms.',
|
body: 'Tool call: test-function. Decision: accept. Success: true. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_TOOL_CALL,
|
'event.name': EVENT_TOOL_CALL,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
function_name: 'test-function',
|
function_name: 'test-function',
|
||||||
@@ -532,6 +547,9 @@ describe('loggers', () => {
|
|||||||
decision: ToolCallDecision.ACCEPT,
|
decision: ToolCallDecision.ACCEPT,
|
||||||
prompt_id: 'prompt-id-1',
|
prompt_id: 'prompt-id-1',
|
||||||
tool_type: 'native',
|
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.',
|
body: 'Tool call: test-function. Decision: reject. Success: false. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_TOOL_CALL,
|
'event.name': EVENT_TOOL_CALL,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
function_name: 'test-function',
|
function_name: 'test-function',
|
||||||
@@ -597,6 +616,9 @@ describe('loggers', () => {
|
|||||||
decision: ToolCallDecision.REJECT,
|
decision: ToolCallDecision.REJECT,
|
||||||
prompt_id: 'prompt-id-2',
|
prompt_id: 'prompt-id-2',
|
||||||
tool_type: 'native',
|
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.',
|
body: 'Tool call: test-function. Decision: modify. Success: true. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_TOOL_CALL,
|
'event.name': EVENT_TOOL_CALL,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
function_name: 'test-function',
|
function_name: 'test-function',
|
||||||
@@ -665,6 +688,9 @@ describe('loggers', () => {
|
|||||||
decision: ToolCallDecision.MODIFY,
|
decision: ToolCallDecision.MODIFY,
|
||||||
prompt_id: 'prompt-id-3',
|
prompt_id: 'prompt-id-3',
|
||||||
tool_type: 'native',
|
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.',
|
body: 'Tool call: test-function. Success: true. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_TOOL_CALL,
|
'event.name': EVENT_TOOL_CALL,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
function_name: 'test-function',
|
function_name: 'test-function',
|
||||||
@@ -731,6 +758,10 @@ describe('loggers', () => {
|
|||||||
success: true,
|
success: true,
|
||||||
prompt_id: 'prompt-id-4',
|
prompt_id: 'prompt-id-4',
|
||||||
tool_type: 'native',
|
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.',
|
body: 'Tool call: test-function. Success: false. Duration: 100ms.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_TOOL_CALL,
|
'event.name': EVENT_TOOL_CALL,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
function_name: 'test-function',
|
function_name: 'test-function',
|
||||||
@@ -802,6 +834,8 @@ describe('loggers', () => {
|
|||||||
'error.type': ToolErrorType.UNKNOWN,
|
'error.type': ToolErrorType.UNKNOWN,
|
||||||
prompt_id: 'prompt-id-5',
|
prompt_id: 'prompt-id-5',
|
||||||
tool_type: 'native',
|
tool_type: 'native',
|
||||||
|
decision: undefined,
|
||||||
|
metadata: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -841,6 +875,7 @@ describe('loggers', () => {
|
|||||||
body: 'Malformed JSON response from test-model.',
|
body: 'Malformed JSON response from test-model.',
|
||||||
attributes: {
|
attributes: {
|
||||||
'session.id': 'test-session-id',
|
'session.id': 'test-session-id',
|
||||||
|
'user.email': 'test-user@example.com',
|
||||||
'event.name': EVENT_MALFORMED_JSON_RESPONSE,
|
'event.name': EVENT_MALFORMED_JSON_RESPONSE,
|
||||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||||
model: 'test-model',
|
model: 'test-model',
|
||||||
|
|||||||
Reference in New Issue
Block a user