Skip to contentSkip to page list

Docs

GitHub Copilot CLI Monitoring and Usage Tracking

Track GitHub Copilot CLI and Copilot Chat usage and cost. Send sessions and traces to LangWatch with the LangWatch command-line tool.

On this page

GitHub Copilot reports its work over OpenTelemetry, in the command-line tool and in the Visual Studio Code chat extension. The LangWatch command-line tool connects that report to your workspace, so you can read the cost of each session, the trace of each turn, and the prompt and the response behind both.

This page covers two surfaces:

  • copilot, the GitHub Copilot command-line tool. Version 1.0.41 or later.
  • code, Visual Studio Code, for the GitHub Copilot Chat extension inside it.

Each one has two ways to set it up:

  • langwatch copilot or langwatch code starts the tool and sets up the connection on the first run. Use it on a machine you work on.
  • langwatch instrument copilot or langwatch instrument code writes the same setup and exits. Use it on a server, or when the telemetry must go to a team project.

langwatch instrument always installs the hook file that links each session to its repository and pull request. The wrapper installs it only when you keep the plain command reporting, and a run that takes the gateway route writes no hook file. See Link sessions to their pull requests.

Before you start

  • Install the GitHub Copilot command-line tool, Visual Studio Code, or both.
  • Install the LangWatch command-line tool: npm install -g langwatch
  • Create an account at app.langwatch.ai, or run your own instance with npx @langwatch/server.

Run Copilot through the wrapper

example.shBash
langwatch login --devicelangwatch copilot

The first run asks one question:

AnswerWhat it does
Using your own copilot planCopilot keeps your own seat and your own login. LangWatch receives telemetry only.
Using an API keyCopilot calls travel through the LangWatch gateway with your own provider keys.

LangWatch remembers the answer, so later runs do not ask again. Everything else is unchanged: langwatch copilot accepts the same flags and the same subcommands as copilot, and it returns the same exit code.

Warning

The gateway answer moves the model spend off your Copilot seat and onto your organization's gateway budget. Pick it only when that is what you want. The command-line tool prints a note about the change every time it takes that route.

For Copilot Chat inside Visual Studio Code, start the editor the same way:

example.shBash
langwatch code

The editor opens as usual, and every chat turn in it reports to LangWatch. Copilot Chat has no gateway option, so it asks no question and always sends telemetry only.

Set up a machine without starting the tool

langwatch instrument copilot writes the connection and exits. A plain copilot run on that machine then sends its telemetry to LangWatch. This is the setup for a server that holds many agents, for a machine image, or for a configuration management run.

example.shBash
langwatch instrument copilotlangwatch instrument code

Each command writes a function of the same name in your shell start file, which applies the LangWatch settings to that tool and to no other command. The file is ~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish. Open a new terminal after the command, or read the start file again, so the function is in place.

The shell function needs zsh, bash or fish. On Windows, start the tool with langwatch copilot or langwatch code each time instead.

For code, LangWatch also removes the same settings from the Visual Studio Code integrated terminal configuration. The editor keeps the key, and the terminals inside it do not.

Both commands also write the LangWatch hook file in your Copilot hooks folder, which reports the repository and branch of each session. See Link sessions to their pull requests.

Choose where the telemetry goes

Pass one scope flag, and one only:

CommandDestination
langwatch instrument copilotYour personal workspace
langwatch instrument copilot --project <id-or-slug>A team project. See Team projects.
langwatch instrument copilot --key <ingest-key>The project that owns the key, with no login. See Headless machines and CI.
langwatch instrument copilot --personalBack to your personal workspace

Replace copilot with code for the Visual Studio Code extension. The two are separate, so you can send the command-line tool to a team project and keep the editor on your personal workspace.

The wrapper accepts the same flags: langwatch copilot --project acme-app pins the project and then starts Copilot. --project and --personal are LangWatch flags; LangWatch removes them from the command line before Copilot reads it.

Remove the setup

example.shBash
langwatch logout

This deletes every connection the command-line tool wrote, for every tool, the Copilot hook file included.

The GitHub Copilot app

The standalone GitHub Copilot app is a separate surface with its own command:

example.shBash
langwatch copilot-app connect

This mints an ingest key and installs a small agent that starts with your session, so every app session is captured without a wrapper. Add --tokens-only to collect the usage numbers and no content.

Not yet available: session rows and pull request cost for the GitHub Copilot app. Its turns arrive as traces.

What you get in LangWatch

Open your personal page at /coding-agents, or open the project you pinned Copilot to.

  • Sessions: one row per Copilot conversation, from the command-line tool and from Copilot Chat in Visual Studio Code alike, with the models it used, its tokens, its token cost and the tools it ran.
  • Repository and branch: with the hook file installed, each row shows the repository and branch the session worked on, and the pull requests that branch maps to.
  • Pull requests: what each pull request cost across every session that drove it, with the tokens of each model.
  • Traces: one trace per turn, with the model, the tokens and the timing of each step.
  • Content: the prompt of each turn and the response of the model.

Microsoft Copilot Studio agents are a separate product and never appear as coding sessions. See Copilot Studio for those.

How Copilot cost is counted

LangWatch prices each model call from its tokens at the model's list price, because Copilot reports no amount of money. That token cost is the dollar figure on sessions and pull requests, and it is not a figure from your Copilot bill.

Copilot also reports AI units on each model call, its own usage count. On a pull request, AI units appear as their own count and never enter the dollar total. A model with no price shows its tokens and an unknown cost, not zero.

Your agent can read all of this back. See Explore your usage with your own agent.

LangWatch reads the repository and branch of a Copilot session from a hook file, not from Copilot's telemetry. langwatch instrument copilot and langwatch instrument code write it to ~/.copilot/hooks/langwatch.json, or to $COPILOT_HOME/hooks/langwatch.json when you set COPILOT_HOME. langwatch ingest install copilot_cli writes the same file.

langwatch copilot and langwatch code write it on the run where you answer yes to keeping the plain command reporting, and later runs put it back if it is missing. A run that takes the gateway route asks no such question, so it writes no hook file.

The file runs langwatch ingest hook copilot on two Copilot events: sessionStart, and agentStop at the end of every turn. The command reads the origin remote, the current branch and the worktree of the session's directory, and sends them to the same destination as the session's telemetry. With GitHub connected, LangWatch maps that branch to its pull requests. See Repository and PR attribution.

LangWatch writes only langwatch.json and never opens your other hook files in that folder. A langwatch.json that LangWatch did not write is left as it is. langwatch logout deletes the file.

Each entry in the file holds the same command for bash and for powershell, so the hook runs on macOS, Linux and Windows.

The hook needs langwatch on your PATH. Copilot runs the command by name, so install the command-line tool with npm install -g langwatch, not through npx alone.

Content and privacy

The setup turns on OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, which is what puts the prompt and the response on the wire. Without it a trace carries the tokens, the model and the timing, and no text.

Set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false in your own environment to keep the content off. LangWatch never overrides that value, and it reports that the traces carry usage only.

Troubleshooting

For more failure modes see CLI debug.

Manual OpenTelemetry setup

Use this when you cannot install the LangWatch command-line tool. The variables below are the ones langwatch instrument copilot writes for you.

GitHub Copilot CLI

example.shBash
export COPILOT_OTEL_ENABLED=trueexport COPILOT_OTEL_EXPORTER_TYPE=otlp-httpexport OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=trueexport OTEL_TRACES_EXPORTER=otlpexport OTEL_METRICS_EXPORTER=otlpexport OTEL_EXPORTER_OTLP_PROTOCOL=http/jsonexport OTEL_EXPORTER_OTLP_ENDPOINT=https://app.langwatch.ai/api/otelexport OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ik-lw-your-ingest-key"export OTEL_RESOURCE_ATTRIBUTES="service.name=copilot-cli"copilot

The header takes an ingest key (ik-lw-…), which can create traces and no other requests. Keep a full project API key (sk-lw-…) out of the configuration of a coding agent: it can read and change your project data, and a coding agent has no use for that.

Copilot reports spans and metrics, and no separate log records, so there is no logs exporter to set. It sends over HTTP only: a grpc protocol value is accepted and then ignored.

Copilot Chat in Visual Studio Code

Same block, without the exporter type, and with the service name of the extension:

example.shBash
export COPILOT_OTEL_ENABLED=trueexport OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=trueexport OTEL_TRACES_EXPORTER=otlpexport OTEL_METRICS_EXPORTER=otlpexport OTEL_EXPORTER_OTLP_PROTOCOL=http/jsonexport OTEL_EXPORTER_OTLP_ENDPOINT=https://app.langwatch.ai/api/otelexport OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ik-lw-your-ingest-key"export OTEL_RESOURCE_ATTRIBUTES="service.name=copilot-chat"code

COPILOT_OTEL_ENABLED takes precedence over the github.copilot.chat.otel.enabled setting of the extension, so the editor reports even with an empty settings file.

For a self-hosted instance, replace the endpoint with the address of your instance followed by /api/otel. Copilot appends /v1/traces and /v1/metrics on its own. Never write the per-signal path yourself.

Warning

A plain export applies the key to every program the shell starts, and Visual Studio Code passes its own environment to every integrated terminal. To keep the key to one tool, put the variables in a shell function. This is the function langwatch instrument copilot writes to your shell rc file:

example.shBash
copilot() {    COPILOT_OTEL_ENABLED=true \    COPILOT_OTEL_EXPORTER_TYPE=otlp-http \    OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true \    OTEL_TRACES_EXPORTER=otlp \    OTEL_METRICS_EXPORTER=otlp \    OTEL_EXPORTER_OTLP_PROTOCOL=http/json \    OTEL_EXPORTER_OTLP_ENDPOINT=https://app.langwatch.ai/api/otel \    OTEL_EXPORTER_OTLP_HEADERS='Authorization=Bearer ik-lw-your-ingest-key' \    OTEL_RESOURCE_ATTRIBUTES=service.name=copilot-cli \    command copilot "$@"}

langwatch instrument code writes the same function for code, without COPILOT_OTEL_EXPORTER_TYPE and with service.name=copilot-chat. On fish, both are a function with set -lx for each variable.

Documentation