Skip to content

Record CAPI X-Copilot-Service-Request-Id on chat telemetry events - #334638

Merged
Vijay Upadya (vijayupadya) merged 2 commits into
microsoft:mainfrom
rohit489:rohit489/CopilotServiceRequestId
Sep 6, 2026
Merged

Record CAPI X-Copilot-Service-Request-Id on chat telemetry events#334638
Vijay Upadya (vijayupadya) merged 2 commits into
microsoft:mainfrom
rohit489:rohit489/CopilotServiceRequestId

Conversation

@rohit489

Copy link
Copy Markdown
Contributor

Captures CAPI's X-Copilot-Service-Request-Id response header and threads it through chat fetch results, error paths, and websocket telemetry, so client-side telemetry events can be joined with CAPI's telemtry.

Also covers the retry-after-error and connectivity-test error paths, and adds a test asserting the id lands on chat response telemetry.

Copilot AI balanced review requested due to automatic review settings September 4, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Several filtering, cancellation, and failed-connectivity paths still discard the new correlation ID.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 2 Medium severity

New issues introduced by this change (2)
Severity Finding
Medium severity extensions/​copilot/​src/​extension/​prompt/​node/​chatMLFetcher.ts — The FetchResponseKind.Failed retry caller destructures only retryResult from…
Medium severity extensions/​copilot/​src/​extension/​prompt/​node/​chatMLFetcherTelemetry.ts — This new cancellation property is populated only by the exception/catch cancellation path. The…
What changed in this PR

Adds CAPI service request IDs to chat results and telemetry for cross-system correlation.

Changes:

  • Extracts and propagates X-Copilot-Service-Request-Id.
  • Adds IDs to HTTP, WebSocket, retry, cancellation, and error telemetry.
  • Updates tests, fixtures, and snapshots.
File Description
extensions/​copilot/​src/​platform/​telemetry/​common/​telemetryData.ts Adds the ID to request telemetry data.
extensions/​copilot/​src/​platform/​networking/​test/​node/​fetch.spec.ts Tests header extraction and casing.
extensions/​copilot/​src/​platform/​networking/​node/​chatWebSocketTelemetry.ts Adds the ID to WebSocket events.
extensions/​copilot/​src/​platform/​networking/​node/​chatWebSocketManager.ts Captures the handshake ID.
extensions/​copilot/​src/​platform/​networking/​common/​networking.ts Extends retry telemetry properties.
extensions/​copilot/​src/​platform/​networking/​common/​fetch.ts Defines extraction helpers and request metadata.
extensions/​copilot/​src/​platform/​endpoint/​test/​node/​messagesApi.spec.ts Updates processor construction.
extensions/​copilot/​src/​platform/​endpoint/​test/​node/​__snapshots__/​stream.sseProcessor.spec.ts.snap Updates request metadata snapshots.
extensions/​copilot/​src/​platform/​endpoint/​node/​test/​responsesApiToolSearch.spec.ts Updates Responses processor fixtures.
extensions/​copilot/​src/​platform/​endpoint/​node/​test/​responsesApi.spec.ts Updates Responses processor tests.
extensions/​copilot/​src/​platform/​endpoint/​node/​responsesApi.ts Propagates the ID through Responses completions.
extensions/​copilot/​src/​platform/​endpoint/​node/​messagesApi.ts Propagates the ID through Anthropic completions.
extensions/​copilot/​src/​platform/​endpoint/​node/​chatEndpoint.ts Adds the ID to non-streaming completions.
extensions/​copilot/​src/​platform/​chat/​common/​commonTypes.ts Extends chat result types.
extensions/​copilot/​src/​extension/​prompt/​node/​test/​chatMLFetcherResponseApiTelemetry.spec.ts Verifies success telemetry correlation.
extensions/​copilot/​src/​extension/​prompt/​node/​chatMLFetcherTelemetry.ts Extends chat telemetry event schemas.
extensions/​copilot/​src/​extension/​prompt/​node/​chatMLFetcher.ts Threads IDs through fetch and retry paths.
extensions/​copilot/​src/​extension/​externalAgents/​node/​oaiLanguageModelServer.ts Propagates IDs for external-agent streaming.
extensions/​copilot/​src/​extension/​completions-core/​vscode-node/​lib/​src/​test/​fetcher.ts Updates completion test metadata.
extensions/​copilot/​src/​extension/​completions-core/​vscode-node/​lib/​src/​openai/​fetch.fake.ts Updates fake completion metadata.
extensions/​copilot/​src/​extension/​completions-core/​vscode-node/​lib/​src/​ghostText/​test/​streamedCompletionSplitter.test.ts Updates ghost-text test metadata.
Suppressed comments (1)

extensions/copilot/src/extension/prompt/node/chatMLFetcher.ts:1938

  • The service request ID is added to FilteredRetry, but the conversion to the final Filtered result at lines 379–385 copies only requestId and serverRequestId. When filtering is not retried (or no retry result is returned), callers therefore still lose the CAPI correlation ID. Forward result.copilotServiceRequestId in that returned result as well.
					copilotServiceRequestId: result.requestId.copilotServiceRequestId,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +873 to +876
const connectivityTestErrorCopilotServiceRequestId = connectivity.connectivityTestErrorCopilotServiceRequestId;
if (!connectivity.retryRequest) {
this._logService.info(`Not retrying chat request as network connectivity could not be re-established.`);
return { connectivityTestError, connectivityTestErrorGitHubRequestId };
return { connectivityTestError, connectivityTestErrorGitHubRequestId, connectivityTestErrorCopilotServiceRequestId };
export interface IChatMLFetcherCancellationProperties {
source: string;
requestId: string;
copilotServiceRequestId?: string;
@vijayupadya
Vijay Upadya (vijayupadya) merged commit 48ac187 into microsoft:main Sep 6, 2026
30 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.137.0 milestone Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants