langwatch opencodestarts opencode and sets up the connection on the first run. Use it on a machine you work on.langwatch instrument opencodewrites the same setup and exits. Use it on a server, or when the telemetry must go to a team project.
Before you start
- Install opencode.
- 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 opencode through the wrapper
LangWatch remembers the answer, so later runs do not ask again. Everything else is unchanged:
langwatch opencode accepts the same flags as opencode and returns the same exit code.
A virtual key is created the first time you choose the gateway, not at login. If you always keep your own providers, LangWatch never creates one for you.
Set up a machine without starting opencode
langwatch instrument opencode writes the connection and exits. A plain opencode 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.
- An
opencodefunction in your shell start file, which applies the LangWatch settings toopencoderuns and to nothing else. The file is~/.zshrc,~/.bashrc, or~/.config/fish/config.fish. - The
experimental.openTelemetryflag in~/.config/opencode/opencode.jsonc. opencode reports nothing without it.
The shell function needs zsh, bash or fish. On Windows, start opencode with
langwatch opencode each time instead.Choose where the telemetry goes
Pass one scope flag, and one only.Send the telemetry to a team project
traces:create permission on the project. See Roles and permissions.
The wrapper accepts the same flags. This pins the project and then starts opencode:
--project and --personal are LangWatch flags. LangWatch removes them from the command line before opencode reads it, so they never reach the agent.
Set up a machine that never logs in
--key takes an ingest key (ik-lw-…). It needs no login and contacts no server, which makes it the option for a shared machine, a build agent, or a base image.
LANGWATCH_INGEST_KEY environment variable:
Move a tool back to your personal workspace
Remove the setup
What you get in LangWatch
Open your personal page at/me, or open the project you pinned opencode to.
- Sessions: one row per opencode session, with the context it carried and how long it worked.
- Traces: one trace per turn, with each model call and each tool call in order.
- Cost: the amount per session and per turn.
- Content: the arguments of each tool call and the result it returned.
Troubleshooting
Nothing arrives in LangWatch
Nothing arrives in LangWatch
Open a new terminal. The
opencode function is read from the shell start file when a shell begins, so a terminal that was already open does not have it.Then check that experimental.openTelemetry is true in ~/.config/opencode/opencode.jsonc. opencode accepts the LangWatch settings and reports nothing while that flag is off.The command reports that it could not write the shell start file
The command reports that it could not write the shell start file
The shell is not zsh, bash or fish. Start opencode with
langwatch opencode each time, which needs no start file.The OpenTelemetry flag stays off
The OpenTelemetry flag stays off
You set
experimental.openTelemetry to false yourself at some point. LangWatch never overrides that choice. Set it to true in ~/.config/opencode/opencode.jsonc, or remove the line and run langwatch instrument opencode again.The telemetry goes to the wrong workspace
The telemetry goes to the wrong workspace
Run
langwatch instrument opencode --project <id-or-slug> to move it to a team project, or langwatch instrument opencode --personal to move it back to your own.Authentication errors
Authentication errors
Check that the key is live and that the header reads
Authorization=Bearer <key>. An ingest key can write traces and nothing else, so a key that works for ingestion still fails on other endpoints.On a machine with a login, run langwatch login --device again to refresh the session.Manual OpenTelemetry setup
Use this when you cannot install the LangWatch command line tool. First turn the reporting on in~/.config/opencode/opencode.jsonc:
langwatch instrument opencode writes for you.
ik-lw-…), which can create traces and nothing else. 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.
For a self-hosted instance, replace the endpoint with the address of your instance followed by /api/otel. opencode appends /v1/traces, /v1/logs and /v1/metrics on its own. Never write the per-signal path yourself.