mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
Telemetry: Improve clarity of user prompt event (#967)
This commit is contained in:
@@ -7,8 +7,12 @@
|
||||
import { logs } from '@opentelemetry/api-logs';
|
||||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
||||
import { Config } from '../config/config.js';
|
||||
import { EVENT_API_RESPONSE } from './constants.js';
|
||||
import { logApiResponse, logCliConfiguration } from './loggers.js';
|
||||
import { EVENT_API_RESPONSE, EVENT_USER_PROMPT } from './constants.js';
|
||||
import {
|
||||
logApiResponse,
|
||||
logCliConfiguration,
|
||||
logUserPrompt,
|
||||
} from './loggers.js';
|
||||
import * as metrics from './metrics.js';
|
||||
import * as sdk from './sdk.js';
|
||||
import { vi, describe, beforeEach, it, expect } from 'vitest';
|
||||
@@ -86,6 +90,56 @@ describe('loggers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('logUserPrompt', () => {
|
||||
const mockConfig = {
|
||||
getSessionId: () => 'test-session-id',
|
||||
getTelemetryLogUserPromptsEnabled: () => true,
|
||||
} as unknown as Config;
|
||||
|
||||
it('should log a user prompt', () => {
|
||||
const event = {
|
||||
prompt: 'test-prompt',
|
||||
prompt_length: 11,
|
||||
};
|
||||
|
||||
logUserPrompt(mockConfig, event);
|
||||
|
||||
expect(mockLogger.emit).toHaveBeenCalledWith({
|
||||
body: 'User prompt. Length: 11',
|
||||
attributes: {
|
||||
'session.id': 'test-session-id',
|
||||
'event.name': EVENT_USER_PROMPT,
|
||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||
prompt_length: 11,
|
||||
prompt: 'test-prompt',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not log prompt if disabled', () => {
|
||||
const mockConfig = {
|
||||
getSessionId: () => 'test-session-id',
|
||||
getTelemetryLogUserPromptsEnabled: () => false,
|
||||
} as unknown as Config;
|
||||
const event = {
|
||||
prompt: 'test-prompt',
|
||||
prompt_length: 11,
|
||||
};
|
||||
|
||||
logUserPrompt(mockConfig, event);
|
||||
|
||||
expect(mockLogger.emit).toHaveBeenCalledWith({
|
||||
body: 'User prompt. Length: 11',
|
||||
attributes: {
|
||||
'session.id': 'test-session-id',
|
||||
'event.name': EVENT_USER_PROMPT,
|
||||
'event.timestamp': '2025-01-01T00:00:00.000Z',
|
||||
prompt_length: 11,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logApiResponse', () => {
|
||||
const mockConfig = {
|
||||
getSessionId: () => 'test-session-id',
|
||||
|
||||
Reference in New Issue
Block a user