diff --git a/extensions/copilot/src/extension/chat/vscode-node/chatDebugFileLoggerService.ts b/extensions/copilot/src/extension/chat/vscode-node/chatDebugFileLoggerService.ts index 8dceb151d3964..3c3162904051e 100644 --- a/extensions/copilot/src/extension/chat/vscode-node/chatDebugFileLoggerService.ts +++ b/extensions/copilot/src/extension/chat/vscode-node/chatDebugFileLoggerService.ts @@ -932,6 +932,9 @@ export class ChatDebugFileLoggerService extends Disposable implements IChatDebug ...(span.attributes[GenAiAttr.USAGE_OUTPUT_TOKENS] !== undefined ? { outputTokens: asNumber(span.attributes[GenAiAttr.USAGE_OUTPUT_TOKENS]) } : {}), + ...(span.attributes[GenAiAttr.USAGE_CACHE_READ_INPUT_TOKENS] !== undefined + ? { cachedTokens: asNumber(span.attributes[GenAiAttr.USAGE_CACHE_READ_INPUT_TOKENS]) } + : {}), ...(span.attributes[CopilotChatAttr.TIME_TO_FIRST_TOKEN] !== undefined ? { ttft: asNumber(span.attributes[CopilotChatAttr.TIME_TO_FIRST_TOKEN]) } : {}), diff --git a/extensions/copilot/src/extension/chat/vscode-node/test/chatDebugFileLoggerService.spec.ts b/extensions/copilot/src/extension/chat/vscode-node/test/chatDebugFileLoggerService.spec.ts index 6ec24ba59bc18..f3233ebc31450 100644 --- a/extensions/copilot/src/extension/chat/vscode-node/test/chatDebugFileLoggerService.spec.ts +++ b/extensions/copilot/src/extension/chat/vscode-node/test/chatDebugFileLoggerService.spec.ts @@ -48,7 +48,7 @@ function makeToolCallSpan(sessionId: string, toolName: string): ICompletedSpanDa }); } -function makeChatSpan(sessionId: string, model: string, inputTokens: number, outputTokens: number): ICompletedSpanData { +function makeChatSpan(sessionId: string, model: string, inputTokens: number, outputTokens: number, cachedTokens?: number): ICompletedSpanData { return makeSpan({ name: 'chat', attributes: { @@ -56,6 +56,7 @@ function makeChatSpan(sessionId: string, model: string, inputTokens: number, out [GenAiAttr.REQUEST_MODEL]: model, [GenAiAttr.USAGE_INPUT_TOKENS]: inputTokens, [GenAiAttr.USAGE_OUTPUT_TOKENS]: outputTokens, + ...(cachedTokens !== undefined ? { [GenAiAttr.USAGE_CACHE_READ_INPUT_TOKENS]: cachedTokens } : {}), [CopilotChatAttr.CHAT_SESSION_ID]: sessionId, }, }); @@ -224,7 +225,7 @@ describe('ChatDebugFileLoggerService', () => { it('writes LLM request with token counts', async () => { await service.startSession('session-1'); - const span = makeChatSpan('session-1', 'gpt-4o', 1000, 500); + const span = makeChatSpan('session-1', 'gpt-4o', 1000, 500, 250); otelService.fireSpan(span); await service.flush('session-1'); @@ -237,6 +238,7 @@ describe('ChatDebugFileLoggerService', () => { expect(attrs.model).toBe('gpt-4o'); expect(attrs.inputTokens).toBe(1000); expect(attrs.outputTokens).toBe(500); + expect(attrs.cachedTokens).toBe(250); }); it('records error status from failed spans', async () => {