Get event-level cost attribution working in five minutes.
- Python 3.9 or newer
- A botanu API key from app.botanu.ai
pip install botanuexport BOTANU_API_KEY=<your-api-key>The SDK auto-configures the OTLP endpoint to https://ingest.botanu.ai and sends the key as a bearer token.
Running your own collector instead? Point at it directly and skip the bearer header:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_SERVICE_NAME=my-serviceimport botanu
with botanu.event(event_id=ticket.id, customer_id=user.id, workflow="Support"):
agent.run(ticket)Every LLM call, HTTP call, and database query inside the block is captured and stamped with event_id, customer_id, and workflow.
For long-lived handlers, a decorator reads cleaner:
import botanu
@botanu.event(
workflow="Support",
event_id=lambda ticket: ticket.id,
customer_id=lambda ticket: ticket.user_id,
)
def handle_ticket(ticket):
return agent.run(ticket)Works for both sync and async def functions.
Break a multi-step event into phases with step:
with botanu.event(event_id=ticket.id, customer_id=user.id, workflow="Support"):
with botanu.step("retrieval"):
docs = vector_db.query(ticket.query)
with botanu.step("generation"):
response = llm.complete(docs)Each phase produces its own span and inherits the event's business context.
| Attribute | Example |
|---|---|
botanu.run_id |
019abc12-3f4d-7... |
botanu.event_id |
ticket-42 |
botanu.customer_id |
acme-corp |
botanu.workflow |
Support |
botanu.environment |
production |
gen_ai.usage.input_tokens |
150 |
gen_ai.usage.output_tokens |
200 |
All spans produced by auto-instrumentation (OpenAI, Anthropic, LangChain, httpx, SQLAlchemy, Redis, ~25 others) inherit these attributes automatically.
The SDK detects existing TracerProvider setups and adds itself alongside without disturbing your sampling ratio. See Coexisting with existing OTel / Datadog.
- Configuration — env vars, YAML, and advanced options
- Concepts: Run Context — what
event_idbuys you - Outcomes — how success/failure is resolved
- Kubernetes Deployment