Skip to content

feat: add OTel invoke_agent spans to inline chat#4151

Open
zhichli wants to merge 5 commits intomainfrom
zhichli/inlineOtel
Open

feat: add OTel invoke_agent spans to inline chat#4151
zhichli wants to merge 5 commits intomainfrom
zhichli/inlineOtel

Conversation

@zhichli
Copy link
Member

@zhichli zhichli commented Mar 3, 2026

Add OTel invoke_agent root spans to inline chat, giving it full observability parity with the foreground agent.

Changes:

  • Wrap both InlineChatEditToolsStrategy and InlineChatEditHeuristicStrategy with invoke_agent InlineChat2Intent root spans
  • All child chat and execute_tool spans auto-nest under the root span
  • Aggregated gen_ai.usage.input/output_tokens on root span (enables single-query token usage for inline chat benchmarks)
  • Record copilot_chat.agent.invocation.duration and copilot_chat.agent.turn.count metrics
  • Emit copilot_chat.session.start and copilot_chat.agent.turn events
  • Error handling with SpanStatusCode.ERROR + error.type

Note on diff size: The raw diff shows +270/-166 but git diff -w (ignoring whitespace) shows only +104 net new lines. The bulk of the diff is re-indentation from wrapping the existing executeEdit() bodies inside startActiveSpan() async callbacks. No behavioral changes to existing logic.

Fixes microsoft/vscode#298885

zhichli added 2 commits March 2, 2026 22:50
Add root invoke_agent spans wrapping both inline chat strategies
(tools and heuristic), giving inline chat full OTel parity with
the foreground agent:

- invoke_agent InlineChat2Intent root span groups all child
  chat and execute_tool spans under a single trace
- Aggregated gen_ai.usage.input/output_tokens on root span
- copilot_chat.agent.invocation.duration metric
- copilot_chat.agent.turn.count metric
- copilot_chat.session.start event per interaction
- copilot_chat.agent.turn event per LLM round-trip
- Error handling with span status and error.type attribute

Fixes microsoft/vscode#298885
Copilot AI review requested due to automatic review settings March 3, 2026 07:09
@vs-code-engineering vs-code-engineering bot added this to the March 2026 milestone Mar 3, 2026
Copy link
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

Adds OpenTelemetry (OTel) invoke_agent root span instrumentation to inline chat edit flows so inline chat has observability parity with the foreground agent, including aggregated token usage, events, and agent-level metrics.

Changes:

  • Wrapes InlineChatEditToolsStrategy and InlineChatEditHeuristicStrategy executions in invoke_agent InlineChat2Intent root spans with GenAI attributes.
  • Emits copilot_chat.session.start / copilot_chat.agent.turn events and records agent duration + turn count metrics.
  • Aggregates token usage onto the root span and sets span status/attributes for completion (and errors in the tools strategy).

alexr00
alexr00 previously approved these changes Mar 3, 2026
emitAgentTurnEvent was receiving cumulative totalInputTokens/totalOutputTokens,
making each subsequent turn event look inflated. Now computes per-turn token
counts from result.fetchResult.usage and emits those, matching the pattern
used in ToolCallingLoop. Accumulated totals are still used for root span
attributes.
zhichli added 2 commits March 3, 2026 09:30
Wrap the InlineChatEditHeuristicStrategy's startActiveSpan callback body
in try/catch to set SpanStatusCode.ERROR and StdAttr.ERROR_TYPE on
failures, matching the tools strategy and toolCallingLoop patterns.
@joaomorenoalt joaomorenoalt removed this from the March 2026 milestone Mar 3, 2026
@zhichli zhichli added this pull request to the merge queue Mar 3, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 3, 2026
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.

Support OTel instrumentation for Inline Chat

5 participants