Claude Code Telemetry: Remove Email, Sum Usage

Resumo

Pixel’s announcement explains how to collect Claude Code token, cost, and session telemetry with a local OpenTelemetry Collector while deleting the user.email field before data is stored. It also highlights that metric points are deltas, so accurate totals require summing every point rather than reading only the latest one.

DEV Community

Claude Code OpenTelemetry: Drop user.email, Sum the Deltas

If you want to record your own or your team's Claude Code telemetry (token, cost and session usage), its OpenTelemetry export (sent over OTLP, the open standard protocol for logs and metrics) will do it, and it writes your signed-in account email onto log records and metric points whenever the email is available. I set up a local OpenTelemetry Collector (a small service that receives and forwards that data) that deletes that field and writes plain JSON lines. Summing the points in those files gives Claude Code token usage and cost totals that add up, as long as no points go missing. When you finish, you have a collector listening only on localhost that keeps session, token and cost records on local disk without the email. One counting rule matters: each metric point (one numeric reading per export) is a delta (only the change since the previous export), so the total is the sum of all points. Reading the last point gives you the wrong number. The OpenTelemetry export carries user.email Turning the export on takes a handful of environment variables. What comes with them is the problem. Claude Code's monitoring docs mark user.email as "Always included when available." They list switches for some other attributes, such as the session ID, account UUID and version. None of the switches covers the email. The fix is a drop processor (the attributes processor with action: delete): one collector rule that deletes a named field before anything is written. In an early trial without the rule, the token usage points carried user.email among 11 attribute keys. With the rule in place, a pre-install trial of two short headless Claude Code sessions against a scratch collector showed the email on 0 of 150 log records and 0 of 14 metric points. The account UUID and organization ID stayed. They are opaque IDs rather than an address, though each is still stable per account, and they are what lets you split usage per account. OpenTelemetry Collector config for Claude Code Claude Code gets the environment block below. The endpoint is the loopback HTTP receiver. The host name and namespace are placeholders. {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:14318",
"OTEL_RESOURCE_ATTRIBUTES": "host.name=,service.namespace="
}
I left OTEL_LOG_USER_PROMPTS and OTEL_LOG_TOOL_DETAILS unset. The docs say prompt content is logged only when the first one is set. Setting or removing any of these keys affects new sessions only. The collector side, with both pipelines: receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
processors:
attributes/drop-email:
actions:
- key: user.email
action: delete
exporters:
file/metrics:
path: /data/metrics.jsonl
format: json
flush_interval: 5s
rotation: {max_megabytes: 100, max_days: 0, max_backups: 0}
file/logs:
path: /data/logs.jsonl
format: json
flush_interval: 5s
rotation: {max_megabytes: 100, max_days: 0, max_backups: 0}
service:
pipelines:
metrics:
receivers: [otlp]
processors: [attributes/drop-email] # memory_limiter and batch omitted here
exporters: [file/metrics]
logs:
receivers: [otlp]
processors: [attributes/drop-email]
exporters: [file/logs]
The real config also has a gRPC receiver, a health check, memory_limiter and batch, and a second exporter on each pipeline that feeds a local SigNoz backend. All listeners bind 127.0.0.1. Processors run before exporters, so the email is gone before any exporter sees the record. max_days: 0 turns off age-based removal, and max_backups: 0 keeps every rotated file. There is no compression key, so the output is plain JSON lines. Why not the obvious approach? Three moves look reasonable at first. I rejected all three: one after testing it, one after it had already ...
Claude Code Telemetry: Remove Email, Sum Usage
Powered by Readybot.io

As últimas novidades de Pixel

Fix GitHub Pages: Missing Artifact Error

Pixel's announcement explains why the GitHub Pages deploy action reports that no github-pages artifact was found. It covers skipped or failed build jobs, missing uploads, …

Rotate DB and Redis Passwords Without Downtime

Pixel shares a practical guide to rotating exposed database and Redis passwords without interrupting application connections. The approach updates Secrets, changes service credentials, and gradually …

AI Agent Receipts Prove What Actually Executed

Pixel’s announcement examines how public Zambo receipts verify what an AI agent actually did. A BTC price fetch succeeded with a recomputable output hash, while …