logo
logo
logo
logo
logo
logo

Jul 31, 2025

Jul 31, 2025

Jul 31, 2025

Jul 31, 2025

Track Claude Code usage and limits with Grafana Cloud

Track Claude Code usage and limits with Grafana Cloud

Track Claude Code usage and limits with Grafana Cloud

Track Claude Code usage and limits with Grafana Cloud

Track Claude Code usage and limits with Grafana Cloud

Track Claude Code usage and limits with Grafana Cloud

by Rafał Strzaliński

If you're running Claude Code across multiple projects or teams, you need to monitor it. You want to know who’s using it, how often, and how much it's costing you – before getting surprised by a massive bill or an internal bottleneck. Without tracking usage, you're flying blind.

There are several ways to set up monitoring for Claude Code. Some of them are... let’s say, ambitious. Take this repo, for example. It hooks up custom logic and scripts to track usage data manually. It works, but it's clunky. Then there’s this setup, which wires everything into OpenTelemetry using full-blown exporters and config chains. Impressive? Sure. 

Another option is to route usage through a proxy like LiteLLM. This can give you centralized control if you’re managing a zoo of LLMs – but if you're only using Claude Code, dragging in LiteLLM just to scrape usage metrics is like renting a crane to hang a picture.

Here’s the better way: Claude Code already supports OpenTelemetry out of the box. No extra services, wrappers, or hacks needed. Just enable OTEL in the config, and send the data straight to a collector. In my case, that collector is a Grafana Cloud OTEL endpoint – free tier, no servers to manage.

It takes five minutes. Once configured, usage metrics flow directly into Grafana. You get visibility, alerts, and dashboards with zero nonsense.

Below, I walk you through the exact setup I use, with screenshots and config examples. 

Setting up Grafana Cloud for Claude Code monitoring

To receive telemetry from Claude Code, we’ll use Grafana Cloud’s built-in OpenTelemetry endpoint. The free tier is enough for basic usage monitoring, and you don’t need to run any collectors yourself. Here’s how to get it set up:

1. Sign up for Grafana Cloud

Go to https://grafana.com and create a free account if you don’t have one yet.

2. Open the Grafana Cloud Portal

After signing in, go to the Grafana Cloud Portal, not the Grafana app UI. This is where you manage your infrastructure, instances, and tokens.
URL: https://grafana.com/orgs/YOUR-ORG/cloud

3. Select your Grafana Cloud instance

In the portal, find your cloud stack and click Details. You’ll see your active services – Grafana, Loki, Tempo, etc.

4. Configure OpenTelemetry

Scroll down to the OpenTelemetry section and click Configure.

5. Generate an API token

Click Create API Token, give it a name, and make sure it has the required OTLP ingest permissions.

Save this token somewhere safe – you’ll need to place it in your Claude Code config later.

Configuring Claude Code to send telemetry

Once your Grafana Cloud endpoint is ready, it's time to configure Claude Code to start sending telemetry. Claude has built-in OpenTelemetry support – no wrappers, no sidecars.

Before launching Claude Code, load these environment variables into your shell:

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp       
export OTEL_LOGS_EXPORTER=otlp          
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-north-0.grafana.net/otlp"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic PLACE_YOUR_TOKEN_HERE"
export OTEL_METRIC_EXPORT_INTERVAL=10000 
export OTEL_LOGS_EXPORT_INTERVAL=5000

Note: remember to replace PLACE_YOUR_TOKEN_HERE with your token

This config enables telemetry, sets up OTLP (OpenTelemetry Protocol) for both logs and metrics, and defines how often data is sent. You don’t need to install any collector – Claude Code handles it internally.

You can check the setup documentation from Anthropic here.

Exploring logs and building a dashboard in Grafana Cloud

Once you’ve connected Claude Code to Grafana Cloud, the logs will show up in Loki, Grafana’s log aggregation backend. Claude emits structured logs for each event, such as api_request or tool_result. You can search and filter them directly in the Explore tab.

Loki supports a query language called LogQL. It lets you extract metrics directly from logs, so that you don’t have to export metrics separately.

What to track on your dashboard

Here are four practical metrics you can extract from Claude Code logs and display in Grafana. They give you clear insights into usage, performance, and cost:

  1. Total API Requests Over Time
    Tracks baseline activity. Helps identify trends and usage spikes over time.

  2. Total Token Usage (Input + Output)
    Measures how much data is sent into and generated by Claude. Essential for cost tracking.

  3. Cost Estimate per Session
    Gives visibility into how expensive each session or user interaction is.

  4. Slow Requests (Latency – P95/P99)
    Useful for spotting performance issues. Focuses on the longest-running requests.

Summary

The built-in OTEL orchestration in Claude Code is the real winner here. This is how every serious tool should ship – especially anything that burns money per use. Native telemetry support, no wrappers, no sidecars, just direct push to your preferred backend.

Grafana Cloud makes a great match. Setup is dead simple, the free tier is enough to get started, and it integrates with Claude Code without any extra infrastructure. You get structured logs in Loki out of the box.

Where things still fall short is dashboarding. Creating a meaningful Grafana dashboard isn't trivial. It takes manual effort, knowledge of PromQL (for metrics), and understanding of LogQL (for logs). On top of that, building a good layout takes time, and Grafana doesn’t help much here.

What we need next is automation – a tool that can import a dashboard template and adapt it to real-time metrics and log structure. Until then, you’ll need to build it the hard way.

That said, with telemetry flowing and logs structured, you’re 90% there. The rest is wiring up the panels – and I’ll cover that in the next chapter.

Table of Content

Title
line

Table of Content

Title
line

Table of Content

Title
line

Table of Content

Title
line

Stay tuned for future releases and more!

© Quesma Inc. 2025

Stay tuned for future releases and more!

© Quesma Inc. 2025

Stay tuned for future releases and more!

© Quesma Inc. 2025

Stay tuned for future releases and more!

© Quesma Inc. 2025

Stay tuned for future releases and more!

© Quesma Inc. 2025

Stay tuned for future releases and more!

© Quesma Inc. 2025