How do I record token counts with OpenLLMetry?
Rius records token counts from your OpenLLMetry traces with no extra attribute or resource setting once the exporter points at Rius. OpenLLMetry’s instrumentation already writes token usage on each model call, and Rius maps it onto its standard token attributes when the trace arrives. Cost is then computed from those counts and the model name. This follows the general path in Trace LLM calls with OpenTelemetry.
How it works
OpenLLMetry has used several attribute conventions across versions, and Rius reads all of them.
- Current releases emit OpenTelemetry GenAI attributes (
gen_ai.*), which Rius reads as sent. - Older releases spell usage as
gen_ai.usage.prompt_tokenswith a matching completion count. Rius moves these ontogen_ai.usage.input_tokensandgen_ai.usage.output_tokensbefore storing the span, and removes the old keys. - A native
gen_ai.*key always wins. The mapping only fills gaps and never overwrites.
So the setting that matters is on the receiving side: the span needs the token counts and a model name, and Rius already normalizes the OpenLLMetry spellings. Cost needs gen_ai.request.model plus at least one of the token counts. A count a span leaves out is read as 0, and a span with no model, an unknown model or no counts gets no cost.
One OpenLLMetry key is not mapped: llm.usage.total_tokens has no canonical equivalent, so it is stored under its own name and does not feed token totals or cost. Input tokens include cached ones and output tokens include reasoning ones.
The full mapping is in the span attribute reference.
Set it up
- Point OpenLLMetry’s exporter at Rius. Use your workspace’s region in the host (the docs show
eu) and an API key from the console.
from traceloop.sdk import Traceloop
Traceloop.init(
app_name="my-agent",
api_endpoint="https://ingest.eu.console.rius-glassflow.com",
headers={"Authorization": "Bearer <your API key>"},
)In Python, remove any old TRACELOOP_BASE_URL or TRACELOOP_HEADERS from the environment, because they override these arguments. Set TRACELOOP_METRICS_ENABLED=false, because Rius ingests traces only and the SDK’s metrics exports otherwise fail with a 404.
-
Run one traced LLM call, open the trace in the Rius console, and check that the model call shows a model name, token counts and cost. The OpenLLMetry page covers the exporter in full.
-
If an older OpenLLMetry release records long agent runs, raise OpenTelemetry’s per-span attribute limit. Those releases write messages one attribute per field, and OpenTelemetry keeps only 128 attributes per span by default, dropping the rest without an error. A span can then lose its model or usage. Set the environment variable
OTEL_SPAN_ATTRIBUTE_COUNT_LIMITto4096in the process that runs OpenLLMetry. The attribute count limit section explains why. -
If you create a model-call span by hand, because no OpenLLMetry instrumentation covers that call, set these attributes on it yourself:
gen_ai.request.modelwith the model name.gen_ai.usage.input_tokenswith the prompt tokens.gen_ai.usage.output_tokenswith the completion tokens.
Add
gen_ai.usage.cache_read.input_tokens,gen_ai.usage.cache_write.input_tokensorgen_ai.usage.reasoning.output_tokensif you have them. Never send a cost attribute, because Rius computes cost itself. -
When you search or filter in trace inspection, use the canonical key
gen_ai.usage.input_tokens. A filter ongen_ai.usage.prompt_tokensmatches nothing, because Rius removes that key after mapping it.
What you get
- Input and output token counts on each model call, taken from your existing OpenLLMetry spans with no re-instrumentation.
- Cost per call, computed by Rius from the model and the token counts. Costs are list-price estimates in US dollars, not billed amounts.
- Cache read, cache write and reasoning counts where your spans carry them, each priced at its own rate.
- Token counts you can search and filter on under one set of keys, whichever OpenLLMetry release produced the span.
When something else fits
- If you have no tracing yet, the Rius SDK sets up token and cost capture for you with one
init()call. See Trace LLM calls with OpenTelemetry for how to choose. - If a span arrives without token counts, check whether a Collector or other processor strips
gen_ai.*keys, or whether the span hit the attribute limit, before changing your instrumentation.