hexr_llm(), Hexr automatically instruments it with OpenTelemetry spans that capture token counts, cost in USD, latency, model version, and the agent role that made the call. No additional configuration is needed — the traces flow to Grafana the moment your agent is deployed. This guide shows what gets captured, how costs are attributed per agent and role, and how to compare providers side by side.
Zero-config tracing
Wrap any LLM client withhexr_llm() and every call generates a full OpenTelemetry span automatically:
my_agent.py
What gets captured
Each LLM span includes the following attributes:| Attribute | Example value |
|---|---|
gen_ai.system | openai |
gen_ai.request.model | gpt-4o |
gen_ai.response.model | gpt-4o-2024-08-06 |
gen_ai.usage.input_tokens | 152 |
gen_ai.usage.output_tokens | 487 |
gen_ai.usage.total_tokens | 639 |
hexr.agent.name | my-agent |
hexr.agent.tenant | acme-corp |
hexr.agent.role | researcher |
hexr.llm.cost_usd | 0.0047 |
hexr.llm.duration_ms | 1234 |
Hexr follows the OpenTelemetry GenAI Semantic Conventions, so traces are compatible with any OTel-compatible backend — Datadog, New Relic, Honeycomb, or Grafana Cloud.
Cost attribution per agent and role
Costs are tracked per agent, per role, and per model. For a CrewAI crew runningresearcher, writer, and editor roles, you’d see a breakdown like this in Grafana:
Cost attribution example
Grafana dashboard
The built-in LLM Costs dashboard shows:- Token usage over time (input vs. output)
- Cost per tenant (bar chart)
- Model distribution (pie chart)
- Latency percentiles (p50, p95, p99)
- Error rate by provider
Comparing providers
Track the same prompt across multiple providers. Each call is traced separately so you can compare cost and latency in Grafana:provider_comparison.py
Next steps
Multi-framework agents
See how per-role cost attribution works in CrewAI and LangChain deployments.
Secure secrets
Store LLM provider API keys with SPIFFE-scoped access and a full audit trail.
Agent-to-agent communication
Trace task delegation across A2A agents alongside LLM spans.
SDK reference
Full reference for
hexr_llm and supported providers.