otellix
OpenTelemetry-native LLM observability and budget guardrails for cost-constrained production environments
About otellix
Otellix
Stop the LLM Bill Shock. Production-grade observability for Go backends â built on OpenTelemetry.

đ¸ The Problem: "Bill Shock" is Real
Most LLM observability tools tell you what you spent after the money is gone. In production, a recursive prompt loop or a single "power user" can rack up thousands in costs before your billing alerts even trigger.
Otellix is different. It brings real-time cost enforcement to the application layer.
⥠Key Features
- đ§Š One-Line SDK Middleware: Already using the official OpenAI or Anthropic Go SDK? Add
option.WithMiddleware(otellixopenai.Middleware(...))and every call is traced, costed and budgeted. Your calls don't change. - âī¸ LangChainGo Integration: Drop-in
callbacks.Handlerfor LangChainGo. Automatic token, cost, and span capture for chains. - đ Automatic Attribution: Capture
user_idandproject_idwith Gin, Echo or Fiber middleware, from your auth or a verified JWT. No more manual context plumbing, and no way for callers to forge their way past a budget. - đī¸ Redis Budget Store: Distributed budget enforcement for high-availability production clusters.
- đ Go-Native & High-Performance: Built for Go 1.22+ using native streaming and OpenTelemetry.
- đ Standard-Compliant (OTel): 100% OTel compliant. Works with Jaeger, Honeycomb, Prometheus, and Grafana.
- đ Prompt Caching ROI: Track exactly how much you save with Anthropic/OpenAI prompt caching.
đ Quick Start
go get github.com/oluwajubelo1/otellix
đšī¸ Try it Locally (Docker)
Want to see the full stack (Prometheus + Grafana) in action? Run our one-liner demo:
curl -sL https://raw.githubusercontent.com/oluwajubelo1/otellix/main/scripts/demo.sh | bash
1. Simple Tracing
Wrap your provider calls to get instant cost attribution and standard OTel spans.
p := openai.New()
result, err := otellix.Trace(ctx, p, params,
otellix.WithUserID("user_456"),
)
2. LangChainGo Integration
Just add the Otellix handler to your LLM configuration.
import "github.com/oluwajubelo1/otellix/integrations/langchaingo"
handler := langchaingo.NewOtellixHandler(
langchaingo.WithProvider("openai"), // required for accurate llm.cost_usd
langchaingo.WithModel("gpt-4o"),
)
p, _ := openai.New(openai.WithCallback(handler))
// Automatically captures token usage, cost, and spans.
res, err := p.GenerateContent(ctx, parts)
The handler records llm.* attributes on a span in the context, or creates its
own llm.call span if none exists, so telemetry is always captured. Set
WithProvider/WithModel (LangChainGo doesn't expose them in its callbacks)
to enable cost tracking.
3. Middleware Attribution
Stop manually passing IDs. The middleware puts each request's user and project on the context, so every LLM call made while handling it is attributed.
import otellixmw "github.com/oluwajubelo1/otellix/middleware"
r := gin.Default()
r.Use(authMiddleware) // your auth: c.Set("user_id", ...), c.Set("org_id", ...)
r.Use(otellixmw.GinMiddleware(
otellixmw.WithUserFromContext("user_id"),
otellixmw.WithProjectFromContext("org_id"),
))
Budgets only apply limits to verified identity, so a caller can't dodge a per-user limit by forging a new user ID. See Verified Identity & Budgets.
4. Local Development
Two dev modes help you see traces while building:
shutdown := otellix.SetupDev() // (1) Pretty summary + raw OTel span JSON
defer shutdown()
shutdown := otellix.SetupDevConsole() // (2) Pretty summary only â clean terminal
defer shutdown()
SetupDev()configures an OpenTelemetry stdout trace exporter (human-readable summary and the raw span JSON) â best for inspecting the exact span payload.SetupDevConsole()prints only the one-line[otellix]summary per call and leaves your existingTracerProvideruntouched â ideal for demos and presentations.RegisterDevPrinter()enables just the summary printer when you already have your ownTracerProviderconfigured.
đ Standardized OTel Attributes
Otellix populates your spans with industry-standard attributes:
| Attribute | Description |
|---|---|
llm.provider | The LLM provider (OpenAI, Anthropic, etc.) |
llm.model | The model used (e.g. claude-sonnet-4-6) |
llm.input_tokens / llm.output_tokens | Token usage for the call |
llm.cache_read_tokens | Tokens served from provider cache (Savings!) |
llm.cost_usd | Real-time USD cost of the call |
đī¸ Supported Providers
Provider wrappers (drop-in Call/Stream):
- Anthropic: Claude Opus/Sonnet/Haiku families with full Prompt Caching metrics.
- OpenAI: GPT-5.x, GPT-4.x, o-series, gpt-oss with caching support.
- Google Gemini: Gemini 3.x, 2.5, 2.0 & 1.5 Pro/Flash.
- Ollama: Local models with zero-dependency streaming.
Pricing-only support (built-in cost table for llm.cost_usd; bring your own provider/API): Kimi (Moonshot), DeepSeek, Qwen, GLM, ERNIE, Hunyuan, Mistral, Grok, plus every model above â 130+ models total. See docs/providers.md.
đ Deep Dives
- Architecture â How Otellix fits into the OTel ecosystem.
- Budget Guardrails â Limits, fallback actions, Redis & InMemory stores.
- Budget Reservations & Cost Estimates â Keeping concurrent calls within a limit, and how costs are estimated.
- Budget Windows â Rolling, daily and monthly budgets, time zones and resets.
- Unpriced Models â Making sure models with no price still count against budgets.
- Cost Attribution â Who spent what, and capping calls with no user.
- Spend Analytics â Breakdowns, monthly forecasts and cheaper-model suggestions from recent calls.
- Metric Labels & Cardinality â Dropping the
user_idlabel so metrics scale to many users. - SDK Middleware â Trace and budget existing OpenAI and Anthropic SDK clients with one option.
- Integrations â LangChainGo setup.
- Middleware & Identity â Gin, Echo and Fiber attribution, verified identity.
- Verified Identity & Budgets â Why budgets only limit verified user and project IDs, and how to set them up.
- Prompt Caching â ROI analysis and tracking.
- Request Deduplication â One provider call for repeated and concurrent identical requests.
đ¤ Contributing
We love stars and contributions! Please see CONTRIBUTING.md. Licensed under MIT.
Frequently Asked Questions
What is otellix?
otellix is a Artificial Intelligence library for the Go programming language. OpenTelemetry-native LLM observability and budget guardrails for cost-constrained production environments
How do I install otellix?
Install otellix with the Go module system using `go get oluwajubelo1/otellix`. Check the repository for the current installation instructions.
What category does otellix belong to?
otellix is listed under Artificial Intelligence, specifically Artificial Intelligence.