Tracing VS Code AI Agent Sessions with OpenTelemetry and Aspire
Visual Studio Codego watch the original →
the gist
You can monitor AI agent activity in VS Code by enabling OpenTelemetry emission and viewing the resulting traces, logs, and tool calls in the .NET Aspire dashboard.
Enabling Agent Telemetry in VS Code
To gain visibility into AI agent behavior, you must enable OpenTelemetry (OTEL) emission within VS Code settings. This allows the editor to export structured logs, traces, and metrics regarding agent tool calls, model switches, and system instructions. You must toggle two specific settings under github.copilot.chat.otel:
github.copilot.chat.otel.enabled: Set totrueto start emitting telemetry data.github.copilot.chat.otel.captureContent: Set totrueto include system instructions, input/output messages, and tool definitions in the trace data.
After updating these settings, reload the VS Code window. The agent will automatically begin emitting data to the default OTEL HTTP endpoint at localhost:4318.
Visualizing Agent Activity with .NET Aspire
.NET Aspire provides a lightweight, open-source dashboard to visualize these traces in real-time. You can launch the dashboard using the Aspire CLI without requiring complex configuration by using the allow-anonymous flag.
aspire dashboard run --allow-anonymous
Once running, the dashboard displays a structured log view where you can inspect individual spans. Each span marked with a sparkle icon contains GenAI-specific metadata, including the model used (e.g., GPT-4o-mini, o1-preview), the full prompt context, and the specific tools invoked by the agent. You can also monitor performance metrics or use the Aspire CLI to stream logs directly to your terminal:
aspire otel logs --endpoint <URL>
This setup allows developers to refine agent instructions by verifying if the system context is too aggressive or if the agent is failing to retrieve necessary file paths during complex tasks.