> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace Visual Studio Code Copilot Chat sessions

> Capture VS Code Copilot Chat agent interactions, LLM calls, tool executions, and token usage in LangSmith via OpenTelemetry.

[Visual Studio Code Copilot Chat](https://code.visualstudio.com/docs/copilot/overview) can export traces over [OpenTelemetry](https://opentelemetry.io/) (OTel). LangSmith ingests OTLP directly, so you can point Copilot Chat at LangSmith and inspect agent turns, model metadata, tool calls, and token usage alongside the rest of your LLM traces.

This guide is based on Copilot's [Monitor agent usage with OpenTelemetry](https://code.visualstudio.com/docs/copilot/guides/monitoring-agents) reference.

## Prerequisites

Before setting up tracing, ensure you have:

* A recent version of [Visual Studio Code](https://code.visualstudio.com/) with GitHub Copilot Chat installed and signed in.
* A [LangSmith API key](/langsmith/create-account-api-key).

## Configure tracing

Copilot Chat enables OTel emission when any of `COPILOT_OTEL_ENABLED`, `OTEL_EXPORTER_OTLP_ENDPOINT`, or the `github.copilot.chat.otel.enabled` setting is set. The simplest way to send Copilot Chat traces to LangSmith is to export the following environment variables before launching VS Code:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export COPILOT_OTEL_ENABLED=true
export COPILOT_OTEL_PROTOCOL=http
export COPILOT_OTEL_ENDPOINT=https://api.smith.langchain.com/otel
export COPILOT_OTEL_CAPTURE_CONTENT=true
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your_langsmith_api_key>,Langsmith-Project=<your_project_name>"
```

| Variable                       | Description                                                                                                                                                                                                              |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `COPILOT_OTEL_ENABLED`         | Set to `true` to enable Copilot Chat OTel export.                                                                                                                                                                        |
| `COPILOT_OTEL_PROTOCOL`        | OTLP protocol. Use `http` to target LangSmith's HTTP OTLP ingestion endpoint.                                                                                                                                            |
| `COPILOT_OTEL_ENDPOINT`        | LangSmith OTLP endpoint. Takes precedence over `OTEL_EXPORTER_OTLP_ENDPOINT`.                                                                                                                                            |
| `COPILOT_OTEL_CAPTURE_CONTENT` | Capture full prompts, responses, tool arguments, and tool results on spans. Off by default.                                                                                                                              |
| `OTEL_EXPORTER_OTLP_HEADERS`   | Authentication headers for the OTLP exporter. Use `x-api-key=<your_langsmith_api_key>` and optionally `Langsmith-Project=<project>` to route traces to a specific [LangSmith project](/langsmith/log-traces-to-project). |

VS Code must inherit these environment variables, so export them in the shell session that launches VS Code (for example, by adding them to `~/.zshrc`, `~/.bashrc`, or a shell profile) before starting the editor.

<Note>
  Update the LangSmith endpoint for self-hosted installations or regional SaaS: GCP EU uses `eu.api.smith.langchain.com`; GCP APAC uses `apac.api.smith.langchain.com`; AWS US uses `aws.api.smith.langchain.com`. For self-hosted LangSmith, append `/api/v1/otel` to your LangSmith API URL—for example, `https://ai-company.com/api/v1/otel`.
</Note>

<Warning>
  `COPILOT_OTEL_CAPTURE_CONTENT=true` records full prompt and response content, system prompts, tool schemas, tool arguments, and tool results. Only enable it in trusted environments where capturing source code, file contents, and user prompts is acceptable.
</Warning>

### Alternative: VS Code settings

If you prefer not to set environment variables, you can enable OTel from VS Code settings instead. Open **Settings** (`⌘,` / `Ctrl+,`), search for `copilot otel`, and configure:

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "github.copilot.chat.otel.enabled": true,
  "github.copilot.chat.otel.exporterType": "otlp-http",
  "github.copilot.chat.otel.otlpEndpoint": "https://api.smith.langchain.com/otel",
  "github.copilot.chat.otel.captureContent": true
}
```

Authentication headers must still be provided through the `OTEL_EXPORTER_OTLP_HEADERS` environment variable—VS Code settings do not expose a header field. Environment variables also take precedence over VS Code settings when both are set.

## View traces in LangSmith

Start a Copilot Chat session and send a request. Open your [LangSmith project](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=langsmith-trace-with-vscode-copilot) to view the resulting traces. Each agent interaction produces a hierarchical span tree following the [OTel GenAI Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/):

* `invoke_agent` spans wrap the full agent orchestration, including agent name, conversation ID, turn count, and total token usage.
* `chat` spans capture individual LLM API calls with model, token counts, response time, and finish reason.
* `execute_tool` spans capture tool invocations with tool name, type, duration, and success status.

When an agent invokes a subagent, Copilot Chat propagates trace context automatically, so the subagent's `invoke_agent` span appears as a child of the parent's `execute_tool` span in LangSmith.

## Troubleshooting

* **No traces appear in LangSmith.** Confirm `COPILOT_OTEL_ENABLED=true` and that VS Code was launched from the shell where the variables are exported. Verify `OTEL_EXPORTER_OTLP_HEADERS` includes `x-api-key=<your_langsmith_api_key>` and that the API key belongs to the workspace you want to trace into. Restart VS Code after changing environment variables.
* **Traces land in the wrong project.** Set `Langsmith-Project=<your_project_name>` in `OTEL_EXPORTER_OTLP_HEADERS`. If unset, traces go to the workspace's `default` project.
* **Prompts and responses are missing.** Content capture is opt-in. Set `COPILOT_OTEL_CAPTURE_CONTENT=true` (or enable the `github.copilot.chat.otel.captureContent` setting).

## Related resources

* [VS Code Copilot: Monitor agent usage with OpenTelemetry](https://code.visualstudio.com/docs/copilot/guides/monitoring-agents)
* [Trace with OpenTelemetry](/langsmith/trace-with-opentelemetry)
* [Log traces to a project](/langsmith/log-traces-to-project)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/langsmith/trace-with-vscode-copilot.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
