Skip to content

Include cached tokens in copilot debug log file output#311188

Open
petercort wants to merge 3 commits intomicrosoft:mainfrom
petercort:petercort-add-cached-token-output
Open

Include cached tokens in copilot debug log file output#311188
petercort wants to merge 3 commits intomicrosoft:mainfrom
petercort:petercort-add-cached-token-output

Conversation

@petercort
Copy link
Copy Markdown

PR implements #311186.

Simply includes the USAGE_CACHE_READ_INPUT_TOKENS as pulled from OTEL. updated the writes LLM request with token counts test with a cachedTokens value.

Testing:

  1. Run unit tests
  2. Build and run the code-oss-dev
  • Open a directory
  • Spawn a GitHub Copilot chat interaction that will hit the LLM
  • Load the debug log, on my macos setup ~/Library/Application Support/code-oss-dev/User/workspaceStorage/<workspace_id>/GitHub.copilot-chat/debug-logs/<session_id>/main.jsonl
  • Search for cachedTokens
    • New output in my testing looks like {"model":"claude-opus-4.6","inputTokens":22891,"outputTokens":229,"cachedTokens":22559,

Copilot AI review requested due to automatic review settings April 18, 2026 18:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements #311186 by extending Copilot Chat’s debug file logging (JSONL) to include cached input token counts derived from OTel spans, aligning file output more closely with the debug UI’s token breakdown.

Changes:

  • Add cachedTokens to llm_request debug log entries when GenAiAttr.USAGE_CACHE_READ_INPUT_TOKENS is present.
  • Update the unit test to emit the cache-read token attribute and assert it is written to the log.
Show a summary per file
File Description
extensions/copilot/src/extension/chat/vscode-node/chatDebugFileLoggerService.ts Emits attrs.cachedTokens in JSONL output for chat spans when the OTel cached-token attribute is present.
extensions/copilot/src/extension/chat/vscode-node/test/chatDebugFileLoggerService.spec.ts Updates the chat span test helper and asserts cachedTokens is logged.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@petercort
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="GitHub"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants