Skip to content

Chat: OTel enrichment for agent context#318031

Merged
zhichli merged 14 commits into
mainfrom
zhichli/oteladdition
May 24, 2026
Merged

Chat: OTel enrichment for agent context#318031
zhichli merged 14 commits into
mainfrom
zhichli/oteladdition

Conversation

@zhichli
Copy link
Copy Markdown
Member

@zhichli zhichli commented May 22, 2026

Overview

What

Adds the canonical github.copilot.* attribute namespace to Copilot Chat's OpenTelemetry output, alongside the existing copilot_chat.* keys. Selected new signals:

  • Git and GitHub context on invoke_agent spans (github.copilot.git.{repository,branch,commit_sha}, github.copilot.github.org).
  • Agent type classifier on invoke_agent (github.copilot.agent.type = builtin | custom).
  • Structured execute_tool parameters for shell, file, skill, and MCP tools (github.copilot.tool.parameters.{command,file_path,edit_type,skill_name,mcp_server_name_hash,mcp_server_name,mcp_tool_name}).
  • Hook decision and duration on execute_hook (github.copilot.hook.{decision,duration,tool_names}).
  • Reasoning token usage under the semantic-convention-aligned key gen_ai.usage.reasoning.output_tokens.

Content-sensitive attributes (raw commands, file paths, MCP server names) are gated on the existing captureContent setting. Identifiers that aren't gated are hashed (SHA-256) where appropriate.

Why

Makes Copilot Chat's OTel output more useful for customer governance, audit, and dashboarding scenarios. The gen_ai.* semantic conventions don't cover Copilot-specific signals (agent type, git context, structured tool parameters, hook outcomes), so a vendor namespace is the right home for them.

Backwards compatibility

All existing copilot_chat.* and gen_ai.usage.reasoning_tokens attributes continue to emit unchanged — the new keys are added in addition, not as a replacement. Downstream consumers (Agent Debug Log, Chronicle, OTLP exporters, the SQLite span store) keep working without modification. Legacy keys are marked in extensions/copilot/docs/monitoring/agent_monitoring.md.

Tests

  • extractToolParameters.spec.ts — shell command truncation/gating; file edit_type classification including VS Code's snake_case tool names; MCP single- and double-underscore name parsing; captureContent gating; unknown-tool fallback.
  • workspaceOTelMetadata.spec.ts — dual-emit of git context; github.copilot.github.org derivation; non-GitHub remote omits org.

Copilot AI review requested due to automatic review settings May 22, 2026 18:17
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 brings VS Code’s Copilot extension OpenTelemetry attributes into parity with the Copilot CLI runtime by introducing the canonical github.copilot.* namespace and dual-emitting it alongside existing legacy keys to preserve downstream compatibility (debug log, Chronicle, OTLP collectors, SQLite span store).

Changes:

  • Add GitHubCopilotAttr constants (plus a SHA-256 helper) and dual-emit git/repo metadata under github.copilot.git.*.
  • Dual-emit the reasoning token metric under gen_ai.usage.reasoning.output_tokens while retaining the legacy key.
  • Enrich spans with agent/tool/hook attributes, including structured github.copilot.tool.parameters.*, plus docs and tests for the new telemetry shape.
Show a summary per file
File Description
extensions/copilot/src/util/node/crypto.ts Adds a sync SHA-256 helper for hashing/redacting telemetry identifiers.
extensions/copilot/src/platform/otel/node/extractToolParameters.ts Introduces structured extraction for tool parameter attributes (shell/file/skill/MCP).
extensions/copilot/src/platform/otel/node/test/extractToolParameters.spec.ts Adds unit tests for structured tool parameter extraction.
extensions/copilot/src/platform/otel/common/workspaceOTelMetadata.ts Dual-emits git/repo metadata into github.copilot.git.* and derives github.copilot.github.org.
extensions/copilot/src/platform/otel/common/test/workspaceOTelMetadata.spec.ts Adds tests for dual-emit behavior and GitHub org derivation.
extensions/copilot/src/platform/otel/common/index.ts Re-exports new constants/types for consumption across the extension.
extensions/copilot/src/platform/otel/common/genAiAttributes.ts Defines the github.copilot.* attribute set and supporting types/constants.
extensions/copilot/src/extension/tools/vscode-node/toolsService.ts Stamps structured github.copilot.tool.parameters.* onto execute_tool spans (gated where needed).
extensions/copilot/src/extension/prompt/node/chatMLFetcher.ts Dual-emits reasoning token usage under the semantic-convention-aligned key.
extensions/copilot/src/extension/intents/node/toolCallingLoop.ts Adds github.copilot.agent.type to invoke_agent spans.
extensions/copilot/src/extension/chat/vscode-node/chatHookService.ts Enriches execute_hook spans with decision/duration/tool_names attributes.
extensions/copilot/docs/monitoring/sprint.plan.md Documents locked design decisions and task breakdown for the telemetry parity sprint.
extensions/copilot/docs/monitoring/agent_monitoring.md Documents namespaces/dual-emit policy and adds github.copilot.* rows (marking legacy keys).
.github/skills/otel/SKILL.md Updates the OTel skill guidance with dual-emit rules and namespace guidance.

Copilot's findings

  • Files reviewed: 14/14 changed files
  • Comments generated: 3

Comment thread extensions/copilot/src/platform/otel/node/extractToolParameters.ts Outdated
Comment thread extensions/copilot/src/platform/otel/common/genAiAttributes.ts Outdated
roblourens
roblourens previously approved these changes May 22, 2026
…xtraction

VS Code's ToolName enum uses snake_case identifiers (create_file,
replace_string_in_file, apply_patch, insert_edit_into_file,
multi_replace_string_in_file, edit_notebook_file, read_file). The
initial CLI-derived FILE_TOOL_NAMES set only contained the Copilot
CLI/Claude camelCase variants, so tool.parameters.edit_type and
tool.parameters.file_path were never emitted on real VS Code tool
spans. Add the missing names and extend classifyEditType to handle
them. Verified end-to-end in Aspire on a trace where create_file now
correctly emits edit_type=create with the file_path gated by
captureContent.
- Move USAGE_REASONING_OUTPUT_TOKENS from GitHubCopilotAttr to GenAiAttr
  (its value is gen_ai.usage.reasoning.output_tokens, not a github.copilot.* key)
- Accept Anthropic-style mcp__server__tool double-underscore format in
  addition to mcp_server_tool single-underscore
- Add a test for the double-underscore variant
@zhichli zhichli changed the title feat(otel): github.copilot.* attribute parity with Copilot CLI runtime Chat: OTel enrichment for agent context May 24, 2026
@zhichli zhichli enabled auto-merge May 24, 2026 06:43
@zhichli zhichli merged commit e638ea5 into main May 24, 2026
25 checks passed
@zhichli zhichli deleted the zhichli/oteladdition branch May 24, 2026 17:18
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 24, 2026
dileepyavan pushed a commit that referenced this pull request May 27, 2026
Chat: OTel enrichment for agent context
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