Rastir — LLM & Agent Observability Library with decorators, metrics, and traces
Project description
Rastir
LLM & Agent Observability — structured tracing and Prometheus metrics via Python decorators, with a built-in collector server.
Full Documentation — Getting Started, Decorators, Adapters, Server Configuration, and more.
Features
- Decorator-based instrumentation —
@trace,@agent,@llm,@tool,@retrieval,@metric - Adapter-based metadata extraction — OpenAI, Anthropic, Bedrock, LangChain, LangGraph (no monkey-patching)
- Nested span support — automatic parent–child linking for agent → LLM → tool call trees
- Built-in collector server — FastAPI ingestion, Prometheus
/metrics, in-memory trace store - Histogram percentiles & exemplars — P50/P95/P99 latency with trace-linked exemplars
- OTLP forwarding — optional export to Tempo, Jaeger, or any OTLP-compatible backend
- Multi-tenant support — tenant isolation via configurable HTTP header
- Zero external dependencies — no database, no Redis, no Kafka; fully stateless
Installation
pip install rastir # Client library only (decorators + HTTP push)
pip install rastir[otel] # + OpenTelemetry SDK & OTLP exporter
pip install rastir[server] # + Collector server (FastAPI, Prometheus, OTLP)
pip install rastir[all] # Everything including dev tools
Quick Start
Client Instrumentation
from rastir import configure, trace, agent, llm, tool, retrieval
configure(
service="my-app",
env="production",
push_url="http://localhost:8080/v1/telemetry",
)
@agent(agent_name="research_agent")
def run_research(query: str) -> str:
context = fetch_docs(query)
return ask_llm(query, context)
@retrieval
def fetch_docs(query: str) -> list[str]:
return vector_db.search(query)
@llm(model="gpt-4o", provider="openai")
def ask_llm(query: str, context: list[str]) -> str:
return openai.chat(messages=[...])
Collector Server
# Start with defaults (0.0.0.0:8080)
rastir-server
# Or via module
python -m rastir.server
Docker
docker build -t rastir-server .
docker run -p 8080:8080 rastir-server
Server Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/telemetry |
Ingest span batches from client libraries |
| GET | /metrics |
Prometheus exposition endpoint |
| GET | /v1/traces |
Query in-memory trace store |
| GET | /health |
Liveness probe |
| GET | /ready |
Readiness probe (queue pressure) |
Configuration
Client (Environment Variables)
| Variable | Default | Description |
|---|---|---|
RASTIR_SERVICE |
unknown |
Service name |
RASTIR_ENV |
development |
Environment |
RASTIR_PUSH_URL |
— | Collector URL |
RASTIR_API_KEY |
— | Optional auth header |
RASTIR_BATCH_SIZE |
100 |
Spans per batch |
RASTIR_FLUSH_INTERVAL |
5 |
Seconds between flushes |
RASTIR_MAX_RETRIES |
3 |
Retry count for transient failures |
RASTIR_SHUTDOWN_TIMEOUT |
5.0 |
Max seconds for graceful shutdown |
Server (Environment Variables or YAML)
| Variable | Default | Description |
|---|---|---|
RASTIR_SERVER_HOST |
0.0.0.0 |
Bind address |
RASTIR_SERVER_PORT |
8080 |
Bind port |
RASTIR_SERVER_MAX_TRACES |
10000 |
Trace store ring buffer size |
RASTIR_SERVER_MAX_QUEUE_SIZE |
50000 |
Ingestion queue limit |
RASTIR_SERVER_OTLP_ENDPOINT |
— | OTLP backend URL |
Prometheus Metrics
| Metric | Type | Labels |
|---|---|---|
rastir_spans_ingested_total |
Counter | service, env, span_type, status |
rastir_llm_calls_total |
Counter | service, env, model, provider, agent |
rastir_tokens_input_total |
Counter | service, env, model, provider, agent |
rastir_tokens_output_total |
Counter | service, env, model, provider, agent |
rastir_tool_calls_total |
Counter | service, env, tool_name, agent |
rastir_retrieval_calls_total |
Counter | service, env, agent |
rastir_errors_total |
Counter | service, env, span_type, error_type |
rastir_duration_seconds |
Histogram | service, env, span_type |
rastir_tokens_per_call |
Histogram | service, env, model, provider |
rastir_ingestion_rejections_total |
Counter | service, env |
rastir_export_failures_total |
Counter | service, env |
rastir_queue_size |
Gauge | — |
Development
Prerequisites
Setup
conda create -n llmobserve python=3.12 -y
conda run -n llmobserve pip install -e ".[all]"
Running Tests
conda run -n llmobserve pytest # all 337 tests
conda run -n llmobserve pytest tests/test_langgraph_integration.py -v # LangGraph integration
Code Quality
conda run -n llmobserve ruff check src/ tests/
conda run -n llmobserve mypy src/
Project Structure
src/rastir/
├── __init__.py # Public API: configure, trace, agent, llm, tool, retrieval
├── config.py # GlobalConfig, ExporterConfig, configure()
├── context.py # Span & agent context (ContextVar-based)
├── decorators.py # @trace, @agent, @llm, @tool, @retrieval, @metric
├── spans.py # SpanRecord data model
├── queue.py # Bounded in-memory span queue
├── transport.py # TelemetryClient + BackgroundExporter
├── adapters/
│ ├── base.py # BaseAdapter interface
│ ├── registry.py # Priority-based adapter resolution
│ ├── openai.py # OpenAI adapter
│ ├── anthropic.py # Anthropic adapter
│ ├── bedrock.py # AWS Bedrock adapter
│ ├── langchain.py # LangChain framework adapter
│ ├── langgraph.py # LangGraph framework adapter
│ ├── retrieval.py # Retrieval adapter
│ ├── tool.py # Tool adapter
│ └── fallback.py # Fallback (always matches)
└── server/
├── __main__.py # python -m rastir.server support
├── app.py # FastAPI application + routes
├── config.py # Server config (YAML + env vars)
├── metrics.py # MetricsRegistry (Prometheus)
├── ingestion.py # IngestionWorker (async queue consumer)
├── trace_store.py # In-memory ring buffer trace store
└── otlp_exporter.py # OTLPForwarder (BatchSpanProcessor)
Documentation
Full documentation is available at skamalj.github.io/rastir:
- Getting Started — Installation, quick start, nested spans
- Decorators —
@trace,@agent,@llm,@tool,@retrieval,@metric - Adapters — OpenAI, Anthropic, Bedrock, LangChain, LangGraph
- Server — Collector server, metrics, histograms, exemplars
- Configuration — Client & server configuration reference
- Contributing Adapters — How to write a custom adapter
License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rastir-0.1.0b1.tar.gz.
File metadata
- Download URL: rastir-0.1.0b1.tar.gz
- Upload date:
- Size: 474.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abda14494a702cfd442a6995007eb87fd2f24f0131c7e98848877cfc01323672
|
|
| MD5 |
d6f358169241c5eade372250efeab978
|
|
| BLAKE2b-256 |
7e2faca9a68336ed1d5e9a7ff8224889d87e1cbce267d608cf15911bfb32773c
|
File details
Details for the file rastir-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: rastir-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 54.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84c9f74ded2947234cdb2f163431496e149d8356564036a62b219db7eaad68d8
|
|
| MD5 |
3cd858f1a04a54be4a37a4f8bde17e2d
|
|
| BLAKE2b-256 |
96e425093353604deb678435d343cb246d23af930677de75eee9e5905107c251
|