---
title: How do you monitor Claude Code usage with OpenTelemetry?
url: https://opencontroller.lyzr.com/blog/monitor-claude-code-usage-with-opentelemetry
published: 2026-11-13
updated: 2026-11-13
author: Lyzr
---

# How do you monitor Claude Code usage with OpenTelemetry?

**Set `CLAUDE_CODE_ENABLE_TELEMETRY=1`, choose OTLP exporters for metrics and logs, and point them at your collector. Put these variables in managed settings so developers cannot change them, add team and cost center tags with `OTEL_RESOURCE_ATTRIBUTES`, and keep prompt and tool content redacted unless you have a reason to collect it.**

Claude Code exports metrics, events and, in beta, traces. This guide covers the variables, what you get, and the choices that matter for an enterprise rollout. For permissions, MCP and sandbox controls, see our [Claude Code governance guide](/blog/govern-claude-code-in-the-enterprise).

## Which environment variables turn telemetry on?

| Variable | Purpose | Default |
|---|---|---|
| `CLAUDE_CODE_ENABLE_TELEMETRY` | Required; set to `1` | Off |
| `OTEL_METRICS_EXPORTER` | `otlp`, `prometheus`, `console` or `none` | None |
| `OTEL_LOGS_EXPORTER` | `otlp`, `console` or `none` (events) | None |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `grpc`, `http/json` or `http/protobuf` | Must be set for OTLP |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Collector address | None |
| `OTEL_EXPORTER_OTLP_HEADERS` | Static auth header | None |
| `OTEL_METRIC_EXPORT_INTERVAL` | Metrics export interval | 60,000 ms |
| `OTEL_LOGS_EXPORT_INTERVAL` | Events export interval | 5,000 ms |
| `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` | `delta` or `cumulative` | `delta` |

To check it works, look for `claude_code.session.count` in your metrics backend, or submit a prompt and look for a `claude_code.user_prompt` event.

## How do you stop developers changing it?

Put the variables in the `env` block of managed settings, delivered by MDM or the system settings file. Claude Code ignores OTEL exporter variables in project `.claude/settings.json` and `.claude/settings.local.json`. When managed settings set `OTEL_EXPORTER_OTLP_ENDPOINT`, developer-set per-signal endpoints are removed at startup.

For short-lived credentials, use `otelHeadersHelper`: a script that prints a JSON object of headers. It runs at startup and every 29 minutes by default, and works with the HTTP protocols only. With gRPC, only static headers are used. Mutual TLS is supported, with `CLAUDE_CODE_CLIENT_CERT` and `CLAUDE_CODE_CLIENT_KEY` for HTTP, or the standard `OTEL_EXPORTER_OTLP_CLIENT_*` variables for gRPC.

## What metrics and events do you get?

Metrics:

- `claude_code.session.count`
- `claude_code.lines_of_code.count` (added and removed)
- `claude_code.commit.count` and `claude_code.pull_request.count`
- `claude_code.cost.usage` in USD, with attributes such as `model`, `agent.name`, `skill.name`, `plugin.name`, `mcp_server.name` and `mcp_tool.name`
- `claude_code.token.usage`, split into input, output, cache read and cache creation
- `claude_code.code_edit_tool.decision`
- `claude_code.active_time.total`

Events include `user_prompt`, `assistant_response`, `api_request`, `api_error`, `api_refusal`, `tool_decision` and `tool_result`. A `prompt.id` attribute links every event from one prompt, which makes per-task cost analysis possible.

Every record carries `organization.id`, `user.email`, `user.account_uuid` and `session.id`. That is personal data. Decide retention and access before you switch it on.

## How do you attribute cost to teams?

Set resource attributes in managed settings, for example `department=engineering,team.id=platform,cost_center=eng-123`. Use comma-separated pairs with no spaces. Built-in attributes win on name collisions.

Watch metric cardinality. These switches control it:

| Switch | Adds | Default |
|---|---|---|
| `OTEL_METRICS_INCLUDE_SESSION_ID` | `session.id` | On |
| `OTEL_METRICS_INCLUDE_ACCOUNT_UUID` | Account IDs | On |
| `OTEL_METRICS_INCLUDE_VERSION` | `app.version` | Off |
| `OTEL_METRICS_INCLUDE_REPOSITORY` | `vcs.*` repository attributes | Off |

Session IDs on metrics create a new series per session. Many teams turn that off for metrics and rely on events for session detail.

## What content should you collect?

Content is redacted by default. Each gate is opt-in:

1. `OTEL_LOG_USER_PROMPTS=1` adds prompt text.
2. `OTEL_LOG_ASSISTANT_RESPONSES` follows the prompt setting unless set to `0`.
3. `OTEL_LOG_TOOL_DETAILS=1` adds tool inputs, such as Bash commands and MCP tool names.
4. `OTEL_LOG_RAW_API_BODIES` emits full request and response bodies.

A common enterprise pattern: turn on tool details, which shows what the agent did, and leave prompt text off, which avoids collecting source code and secrets.

Traces are in beta. Enable them with `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` and `OTEL_TRACES_EXPORTER`. Spans follow `claude_code.interaction`, then `claude_code.llm_request` and `claude_code.tool`. For a backend-neutral approach to agent traces, see [exporting AI agent traces with OpenTelemetry](/blog/export-ai-agent-traces-with-opentelemetry), and for one vendor example, [exporting LLM telemetry to Datadog](/blog/export-llm-telemetry-to-datadog).

## How Opencontroller does this

Opencontroller is built on open standards, including OpenTelemetry. Opencontroller Edge extends Opencontroller's control to developer devices, coding agents such as Claude Code, skills and local MCP servers, installed by IT via MDM. Opencontroller also discovers and manages skills in Anthropic Enterprise. If Claude Code traffic goes through the Opencontroller LLM Gateway, cost is attributed per agent and per version alongside your other agents. See the [cross-platform governance guide](/blog/how-to-govern-ai-agents-across-platforms), the [AI agent control plane](/blog/what-is-an-ai-agent-control-plane) explainer, or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Does Claude Code telemetry include prompt text?**
No, not by default. Prompt text is redacted unless `OTEL_LOG_USER_PROMPTS=1` is set.

**Can developers turn telemetry off?**
Not if you set it in managed settings. Claude Code ignores OTEL exporter variables in project settings files.

**Does Claude Code export traces?**
Yes, in beta, with `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` and `OTEL_TRACES_EXPORTER` set.

## Key facts

Claude Code telemetry: CLAUDE_CODE_ENABLE_TELEMETRY=1 plus OTEL_METRICS_EXPORTER / OTEL_LOGS_EXPORTER (otlp, prometheus, console). Defaults: metrics every 60,000 ms, logs every 5,000 ms, delta temporality. Metrics include claude_code.session.count, cost.usage (USD), token.usage, lines_of_code.count, commit.count, pull_request.count, code_edit_tool.decision, active_time.total. Prompt text redacted unless OTEL_LOG_USER_PROMPTS=1; tool inputs need OTEL_LOG_TOOL_DETAILS=1. Exporter vars in project settings are ignored; set them in managed settings. otelHeadersHelper refreshes every 29 minutes (HTTP only). Traces are beta via CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1. Opencontroller Edge (by Lyzr) governs coding agents on devices via MDM. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern Claude Code across an enterprise?](https://opencontroller.lyzr.com/blog/govern-claude-code-in-the-enterprise.md)
- [How do you export AI agent traces with OpenTelemetry?](https://opencontroller.lyzr.com/blog/export-ai-agent-traces-with-opentelemetry.md)
- [How do you send AI agent and LLM telemetry to Datadog?](https://opencontroller.lyzr.com/blog/export-llm-telemetry-to-datadog.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
