Your app's data
OpenTelemetry Collector
Export traces from a Collector over OTLP/HTTP and set the customer on spans with a processor.
If your services already send traces to an OpenTelemetry Collector, add an otlphttp exporter that sends them to the OTLP receiver at https://www.aispendbook.com/api/v1/ingest/otlp/v1/traces, with an ingestion key in the Authorization header. The receiver has not been run against a live collector.
otel-collector.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
# Copy your own tenant attribute onto the names AI Spendbook reads.
transform/spendbook:
trace_statements:
- context: span
statements:
- set(attributes["spendbook.customer_id"], attributes["tenant.id"]) where attributes["tenant.id"] != nil
- set(attributes["spendbook.feature"], resource.attributes["service.name"]) where attributes["spendbook.feature"] == nil
# At most 500 usage spans are accepted per request.
batch:
send_batch_size: 200
send_batch_max_size: 500
exporters:
otlphttp/spendbook:
traces_endpoint: https://www.aispendbook.com/api/v1/ingest/otlp/v1/traces
headers:
Authorization: "Bearer ${env:SPENDBOOK_API_KEY}"
compression: gzip # or none
encoding: proto # or json
service:
pipelines:
traces/spendbook:
receivers: [otlp]
processors: [transform/spendbook, batch]
exporters: [otlphttp/spendbook]The exporter
| Setting | Value |
|---|---|
| traces_endpoint | https://www.aispendbook.com/api/v1/ingest/otlp/v1/traces. With endpoint instead, set https://www.aispendbook.com/api/v1/ingest/otlp and the exporter adds /v1/traces. |
| headers.Authorization | Bearer followed by an ingestion key (afk_). Keep the key in an environment variable or your secret store. |
| compression | gzip or none. Other compressions are answered with 415. |
| encoding | proto or json. The response comes back in the same encoding. |
| batch | At most 500 usage spans per request. The body limit is 5 MB, also after gzip is decompressed. |
Setting the customer on spans
- The receiver reads
spendbook.customer_idandspendbook.featurefrom each span's attributes, then from the resource's attributes. A span with neither arrives unattributed. - The
transformprocessor above copies atenant.idattribute your code already sets ontospendbook.customer_id, and uses the service name as the feature where none is set. Replacetenant.idwith your own attribute name. - The
transformandattributesprocessors ship in the Collector's contrib distribution (otelcol-contrib).
attributes processor
processors:
# The same with the attributes processor: one fixed customer for everything this collector sends.
attributes/spendbook:
actions:
- key: spendbook.customer_id
value: acme
action: upsertWhat the receiver keeps
- Spans with model usage attributes (
gen_ai.*, the OpenLLMetry names orllm.*) become usage events. Other spans are ignored, so you can send a whole pipeline. Agent, workflow, chain and tool wrapper spans are ignored too, so usage is not counted twice. - A span sent again is a duplicate, never a second event. The event id is built from the trace id and span id, so collector retries are safe.
- The response carries
X-Spans-Accepted,X-Spans-Duplicates,X-Spans-IgnoredandX-Spans-Rejectedheaders, and rejected spans are listed inpartialSuccess. The full mapping is on the OpenTelemetry traces page. - One collector can send the same traces to AI Spendbook and to Datadog or Honeycomb; the fan-out config is on Vercel AI SDK, LangChain and agents.
Check it works
- In the app, open Integrations. Under Add a source, find SDK / HTTP ingestion and choose Set up.
- Go to the Test event step. Use the key you just created, or paste the one your service uses, and choose Send test event.
- Wait for the Test event received notice. It means the key and the ingestion API work. If you see Accepted, but not visible yet, choose Send again after a minute. The test event has zero tokens, so it adds no cost, and it carries the feature
spendbook-connection-testso you can filter it out. - The test event checks the key. Then send one traced model call through the collector and open Usage Explorer: it should appear with its model, token counts and the customer the processor set. The collector's own logs show export errors, such as 401 for a wrong key or 415 for an encoding the receiver doesn't accept.