# Claude Code Monitoring and analytics

> Claude Code: OpenTelemetry, analytics dashboards, usage/cost events, traceparent, privacy controls, team metrics and Passion8 boundaries.

URL: https://docs.passion8.cc/en/docs/claude-code/monitoring
Language: en
Publisher: Passion8

Code offers configurable local/enterprise OpenTelemetry and Anthropic organizational analytics. They serve different purposes.

| Capability | Best fit |
| --- | --- |
| OpenTelemetry | Export usage, costs, tools and traces to enterprise systems |
| Analytics | Organizational adoption, activity, accepted lines and spend |
| /usage, /cost, status line | Individual session and plan visibility |
| Passion8 console | Gateway balance, requests and actual charges |




Local OTel works through Passion8, but Anthropic analytics may not reflect third-party billing. Passion8 is authoritative for its balance and charges.




## OpenTelemetry quickstart

```bash
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-token"

claude
```

Shorten export intervals for diagnostics:

```bash
export OTEL_METRIC_EXPORT_INTERVAL=10000
export OTEL_LOGS_EXPORT_INTERVAL=5000
```

Avoid overly short production intervals that burden clients and collectors.

## Administrator delivery

Enable through managed settings:

```json title="managed settings"
{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "http://collector.example.com:4317",
    "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer example-token"
  }
}
```

Managed environment settings have high priority. OTEL variables are not automatically forwarded to Bash, hooks, MCP or language servers; configure those separately.

## Common environment variables

| Variable | Purpose |
| --- | --- |
| CLAUDE_CODE_ENABLE_TELEMETRY | Enable telemetry |
| `OTEL_METRICS_EXPORTER` | `otlp`、`prometheus`、`console`、`none` |
| `OTEL_LOGS_EXPORTER` | `otlp`、`console`、`none` |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `grpc`、`http/json`、`http/protobuf` |
| OTEL_EXPORTER_OTLP_ENDPOINT | Collector address |
| OTEL_EXPORTER_OTLP_HEADERS | Static auth headers |
| OTEL_METRIC_EXPORT_INTERVAL | Metric interval |
| OTEL_LOGS_EXPORT_INTERVAL | Log interval |
| OTEL_LOG_USER_PROMPTS | Raw prompts |
| OTEL_LOG_ASSISTANT_RESPONSES | Assistant text |
| OTEL_LOG_TOOL_DETAILS | Arguments, commands and MCP names |
| OTEL_LOG_TOOL_CONTENT | Tool payloads in traces |
| OTEL_LOG_RAW_API_BODIES | Full request/response bodies; highest sensitivity |
| CLAUDE_CODE_OTEL_HEADERS_HELPER_DEBOUNCE_MS | Dynamic-header refresh interval |




Keep raw API logging off by default; it can contain complete history, files, tools and secrets. Enable only briefly in isolated diagnostics.




## Metrics cardinality

High-cardinality labels raise storage costs. Available controls:

| Variable | Default | Purpose |
| --- | --- | --- |
| OTEL_METRICS_INCLUDE_SESSION_ID | true | Include session identifier |
| OTEL_METRICS_INCLUDE_VERSION | false | Include client version |
| OTEL_METRICS_INCLUDE_ACCOUNT_UUID | true | Include account identifier |
| OTEL_METRICS_INCLUDE_ENTRYPOINT | false | Include entry point |
| OTEL_METRICS_INCLUDE_RESOURCE_ATTRIBUTES | true | Resource attributes as point labels |

For team dimensions:

```bash
export OTEL_RESOURCE_ATTRIBUTES="department=engineering,team.id=platform,cost_center=eng-123"
```

Avoid spaces and random high-cardinality values here.

## Traces

Tracing requires the additional beta switch:

```bash
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
export OTEL_TRACES_EXPORTER=otlp
```

Each prompt creates a claude_code.interaction root span with model, tool and hook children. Subagent spans attach beneath the parent Agent tool span.

```text
claude_code.interaction
├── claude_code.llm_request
├── claude_code.hook
└── claude_code.tool
    ├── claude_code.tool.blocked_on_user
    ├── claude_code.tool.execution
    └── subagent claude_code.llm_request / claude_code.tool
```

Bash/PowerShell receive TRACEPARENT when tracing is on. Custom providers do not receive it by default; explicitly enable propagation when required:

```bash
export CLAUDE_CODE_PROPAGATE_TRACEPARENT=1
```

## Analytics dashboard

| Plan | URL | Content |
| --- | --- | --- |
| Team/Enterprise | https://claude.ai/analytics/claude-code | Usage, contributions, leaderboard and CSV |
| Console API | https://platform.claude.com/claude-code | Usage, spend and team insights |

Contribution metrics require GitHub integration and organization settings. They cover assisted PRs, lines, acceptance and users. ZDR organizations see usage only.

Console analytics includes accepted lines, acceptance rate, activity, spend and user insights. Spend is an estimate; billing remains authoritative.

## Caching and cost effects

| Action | Effect |
| --- | --- |
| Metrics/logs | No prompt changes; usually no cache effect |
| Tracing | No prompt changes; possible export overhead |
| Raw content logging | No cache effect but substantial privacy/storage risk |
| /usage and /cost | Local/account display without prefix changes |
| Status-line costs | Local script, no model call |

Optimize Passion8 costs with [caching](https://docs.passion8.cc/en/docs/claude-code/prompt-caching), [cost controls](https://docs.passion8.cc/en/docs/claude-code/cost-saving) and the Passion8 console, not only Anthropic analytics.

## Official references

- [Monitoring with OpenTelemetry](https://code.claude.com/docs/en/monitoring-usage.md)
- [Track team usage with analytics](https://code.claude.com/docs/en/analytics.md)
- [Status line](https://code.claude.com/docs/en/statusline.md)
- [Manage costs effectively](https://code.claude.com/docs/en/costs.md)
