
metrics
OpenTelemetry and OpenInference telemetry pipeline for Claude Code sessions: documentation effectiveness, agent performance, tool usage, and cost metrics
- version
- 0.3.0
- GitHub stars
- 123
Install
/plugin install metrics@ai-helpersRun it inside Claude Code after adding the marketplace with /plugin marketplace add openshift-eng/ai-helpers.
Contents
Discovered from sourceAgents 1
metrics
Automatic OpenTelemetry and OpenInference telemetry for Claude Code CLI sessions.
Receives Claude Code's native OTLP telemetry, maps it to OpenInference semantic conventions, and writes enriched spans to a local JSONL file and MLflow.
No commands. otelcol-contrib starts automatically on SessionStart and stops on SessionEnd.
Architecture
Claude Code CLI
| OTLP/HTTP (spans + metrics + logs)
v
otelcol-contrib
receivers: otlp/http:4318, otlp/grpc:4317
processors: resource → transform/openinference → batch
exporters: file → ~/.local/share/claude-metrics/claude-metrics.jsonl
mlflow → http://localhost:5001
Setup
After installing the plugin, start a Claude Code session. If setup hasn't run you'll see:
metrics plugin: run 'bash /path/to/plugin/scripts/install.sh' once, then restart Claude Code
Run that command — it installs otelcol-contrib and writes the required OTLP env vars to ~/.claude/settings.json. Restart Claude Code. Traces are written to ~/.local/share/claude-metrics/claude-metrics.jsonl; collector logs to ~/.local/share/claude-metrics/otelcol.log.
To add team/repo context to every span:
export OTEL_RESOURCE_ATTRIBUTES="team.name=my-team,repo.name=my-repo,agentic_doc.version=$(git rev-parse HEAD)"
MLflow Integration
MLflow export is enabled by default. Start MLflow before a Claude Code session:
mlflow server --host 127.0.0.1 --port 5001
To change the server or experiment, edit config/otelcol.yaml:
otlp_http/mlflow:
endpoint: http://localhost:5001 # base URL only — otelcol appends /v1/traces
headers:
x-mlflow-experiment-id: "0" # "0" = default experiment
MLflow 3.x accepts OTLP/HTTP at /v1/traces (gRPC not supported). The x-mlflow-experiment-id header is required.
What Gets Collected
Spans (requires CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1):
| Span | What it represents |
|---|---|
claude_code.interaction | One agent turn (prompt → response) |
claude_code.llm_request | One Anthropic API call — model, input_tokens, output_tokens, latency_ms |
claude_code.tool | Tool invocation — tool_name, tool_duration_ms |
claude_code.tool.execution | Actual tool execution |
Metrics: claude_code.token.usage, claude_code.cost.usage, claude_code.session.count, claude_code.lines_of_code.count, claude_code.code_edit.tool_decision.
Log events: claude_code.user_prompt, claude_code.tool_result, claude_code.api_request, claude_code.api_error.
The transform/openinference processor maps these to openinference.span.kind, llm.token_count.*, tool.name, and input/output.value — see config/otelcol.yaml for the full mapping.
Environment Variables
Set by scripts/install.sh — no manual configuration needed.
| Variable | Value |
|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | 1 |
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA | 1 |
OTEL_TRACES_EXPORTER | otlp |
OTEL_METRICS_EXPORTER | otlp |
OTEL_LOGS_EXPORTER | otlp |
OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf |
OTEL_EXPORTER_OTLP_ENDPOINT | http://127.0.0.1:4318 |
OTEL_SERVICE_NAME | claude-code-agent |
OTEL_LOG_USER_PROMPTS | 1 — prompt text in spans |
OTEL_LOG_TOOL_DETAILS | 1 — tool input arguments |
OTEL_LOG_TOOL_CONTENT | 1 — full tool input/output bodies |
OTEL_LOG_RAW_API_BODIES | 1 — Anthropic API request/response JSON |
Optional: OTEL_RESOURCE_ATTRIBUTES, OTEL_METRIC_EXPORT_INTERVAL, OTEL_LOGS_EXPORT_INTERVAL, OTEL_TRACES_EXPORT_INTERVAL.
References
Hooks 2
Sponsors
Details
- Marketplace
- openshift-eng/ai-helpers
- Source
- plugins/metrics
- Category
- Tooling
- Keywords
- opentelemetry, otel, openinference, metrics, tracing, documentation-effectiveness, mlflow, observability
More from openshift-eng/ai-helpers
All 56- must-gatherv0.0.3
- native-notificationsv0.0.2
- nid-teamv0.2.2
- nodev0.0.3
- node-bugv0.0.3
- node-cvev0.0.8
- node-onboardingv0.0.3
- node-rpmv0.0.3
- node-teamv1.0.1
- node-tuningv1.0.1
- olmv0.1.3
- olm-teamv0.2.1
- openshiftv0.0.8
- openshift-developerv1.1.42
- openshift-tls-profilev0.0.2
- operator-dashboardv0.0.1
- originv0.0.2
- ote-migrationv0.0.3
- patternfly
- prodsec-skillsv1.0.0
- prow-agentv0.0.7
- rds-analyzerv0.0.2
- sessionv0.0.2
- snowflakev0.5.1