mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-22 01:37:50 +00:00
feat(client/compression): Log telemetry when compressing chat context. (#6195)
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
logUserPrompt,
|
||||
logToolCall,
|
||||
logFlashFallback,
|
||||
logChatCompression,
|
||||
} from './loggers.js';
|
||||
import { ToolCallDecision } from './tool-call-decision.js';
|
||||
import {
|
||||
@@ -43,12 +44,15 @@ import {
|
||||
ToolCallEvent,
|
||||
UserPromptEvent,
|
||||
FlashFallbackEvent,
|
||||
makeChatCompressionEvent,
|
||||
} from './types.js';
|
||||
import * as metrics from './metrics.js';
|
||||
import * as sdk from './sdk.js';
|
||||
import { vi, describe, beforeEach, it, expect } from 'vitest';
|
||||
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';
|
||||
|
||||
describe('loggers', () => {
|
||||
const mockLogger = {
|
||||
@@ -68,6 +72,45 @@ describe('loggers', () => {
|
||||
vi.setSystemTime(new Date('2025-01-01T00:00:00.000Z'));
|
||||
});
|
||||
|
||||
describe('logChatCompression', () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(metrics, 'recordChatCompressionMetrics');
|
||||
vi.spyOn(ClearcutLogger.prototype, 'logChatCompressionEvent');
|
||||
});
|
||||
|
||||
it('logs the chat compression event to Clearcut', () => {
|
||||
const mockConfig = makeFakeConfig();
|
||||
|
||||
const event = makeChatCompressionEvent({
|
||||
tokens_before: 9001,
|
||||
tokens_after: 9000,
|
||||
});
|
||||
|
||||
logChatCompression(mockConfig, event);
|
||||
|
||||
expect(
|
||||
ClearcutLogger.prototype.logChatCompressionEvent,
|
||||
).toHaveBeenCalledWith(event);
|
||||
});
|
||||
|
||||
it('records the chat compression event to OTEL', () => {
|
||||
const mockConfig = makeFakeConfig();
|
||||
|
||||
logChatCompression(
|
||||
mockConfig,
|
||||
makeChatCompressionEvent({
|
||||
tokens_before: 9001,
|
||||
tokens_after: 9000,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(metrics.recordChatCompressionMetrics).toHaveBeenCalledWith(
|
||||
mockConfig,
|
||||
{ tokens_before: 9001, tokens_after: 9000 },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('logCliConfiguration', () => {
|
||||
it('should log the cli configuration', () => {
|
||||
const mockConfig = {
|
||||
|
||||
Reference in New Issue
Block a user