Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Add cached-token telemetry to align with Copilot CLI - #5076

Open
Patrick McGannon (pmcgannon22) wants to merge 2 commits into
microsoft:mainfrom
pmcgannon22:f/cache-tokens
Open

Add cached-token telemetry to align with Copilot CLI#5076
Patrick McGannon (pmcgannon22) wants to merge 2 commits into
microsoft:mainfrom
pmcgannon22:f/cache-tokens

Conversation

@pmcgannon22

Copy link
Copy Markdown

Problem

Cached-token telemetry in Copilot Chat was incomplete and did not fully align with Copilot CLI.

Fix

Propagate cached token usage through the shared telemetry pipeline and emit both cache-read and cache-creation token signals in OTel.

Changes

  • add cache_creation_input_tokens to shared usage types
  • propagate cache creation tokens through the Anthropic messages API path
  • record cache read and cache creation token usage in OTel metrics
  • add corresponding OTel span attributes
  • preserve zero-valued cached token fields across GitHub, Anthropic BYOK, and Gemini BYOK paths
  • add tests for the new token types

…xporters.ts:20-35.

    serializeSpan() is using old OTel v1 ReadableSpan fields: span.instrumentationLibrary and span.parentSpanId. This repo resolves ReadableSpan from OTel v2, where those are instrumentationScope and parentSpanContext
    (node_modules/@opentelemetry/sdk-trace-node/node_modules/@opentelemetry/sdk-trace-base/build/src/export/ReadableSpan.d.ts:5-23).
@pmcgannon22

Copy link
Copy Markdown
Author

Patrick McGannon (@pmcgannon22) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@alexdima

Copy link
Copy Markdown
Member

Thanks for the contribution! This repository has been archived because the project has moved into the main VS Code repository.

Could you please reopen/recreate this PR against:
https://github.com/microsoft/vscode/tree/main/extensions/copilot

We’ll continue reviewing contributions there. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants