Cloud Native Observability SDK for LLM applications
Project description
Observicia SDK
Observicia is a Cloud Native observability and policy control SDK for LLM applications. It provides seamless integration with CNCF native observability stack while offering comprehensive token tracking, policy enforcement, and PII protection capabilities.
Features
-
Token Tracking and Management
- Real-time token usage monitoring across providers
- Stream-aware token counting
- Token usage retention and cleanup
- Per-session token tracking
-
Policy Enforcement
- Integration with Open Policy Agent (OPA)
- Support for multiple policy evaluation levels
- Risk level assessment (low, medium, high, critical)
- Custom policy definition support
- Synchronous and asynchronous policy evaluation
-
LLM Provider Integration
- OpenAI (fully implemented)
- Chat completions (sync/async)
- Text completions (sync/async)
- Embeddings
- Image generation
- File operations
- Streaming support
- Basic scaffolding for:
- Anthropic
- LiteLLM
- WatsonX
- OpenAI (fully implemented)
-
Observability Features
- OpenTelemetry integration
- Span-based tracing for all LLM operations
- Configurable logging (console, file, OTLP)
- Mermaid diagram generation from telemetry data
- Detailed request/response tracing
- Custom attribute tracking
Quick Start
- Install the SDK:
pip install observicia
- Create a configuration file (
observicia_config.yaml):
service_name: patient-rag-app
otel_endpoint: null
opa_endpoint: http://opa-server:8181/
policies:
- name: pii_check
path: policies/pii
description: Check for PII in responses
required_trace_level: enhanced
risk_level: high
- name: prompt_compliance
path: policies/prompt_compliance
description: Check for prompt compliance
required_trace_level: basic
risk_level: medium
logging:
file: "rag-app.json"
telemetry:
enabled: true
format: "json"
messages:
enabled: true
level: "INFO"
chat:
enabled: true
level: "both"
file: "rag-chat.json"
- Initialize in your code:
from observicia import init
# Initialize Observicia
init()
# Then import openai to so that OpenAI code is instrumented
from openai import OpenAI
client = OpenAI()
Deployment
Prerequisites
- Kubernetes cluster with:
- OpenTelemetry Collector
- Open Policy Agent
- Jaeger (optional)
- Prometheus (optional)
Example Kubernetes Deployment
The SDK includes Kubernetes manifests for deploying:
- OpenTelemetry Collector
- Open Policy Agent
- Jaeger
- Prometheus
- PII detection service
- Prompt compliance service
See the deploy/k8s directory for complete deployment manifests.
Examples
The SDK includes two example applications:
-
Simple Chat Application (examples/simple-chat)
- Basic chat interface using OpenAI
- Demonstrates token tracking and tracing
- Shows streaming response handling
-
RAG Application (examples/rag-app)
- Retrieval-Augmented Generation example
- Shows policy enforcement for PII protection
- Demonstrates context tracking
Architecture
flowchart TB
App[Application] --> SDK[Observicia SDK]
SDK --> Providers[LLM Providers]
SDK --> OPA[Open Policy Agent]
SDK --> OTEL[OpenTelemetry Collector]
OTEL --> Jaeger[Jaeger]
OTEL --> Prom[Prometheus]
OPA --> PII[PII Detection Service]
OPA --> Compliance[Prompt Compliance Service]
Core Components
- Context Manager: Manages trace context and session tracking
- Policy Engine: Handles policy evaluation and enforcement
- Token Tracker: Monitors token usage across providers
- Patch Manager: Manages LLM provider SDK instrumentation
- Tracing Manager: Handles OpenTelemetry integration
Development Status
- ✅ Core Framework
- ✅ OpenAI Integration
- ✅ Basic Policy Engine
- ✅ Token Tracking
- ✅ OpenTelemetry Integration
- 🚧 Additional Provider Support
- 🚧 Advanced Policy Features
- 🚧 UI Components
License
This project is licensed under the Apache License 2.0 - see the LICENSE file 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 observicia-0.1.7.tar.gz.
File metadata
- Download URL: observicia-0.1.7.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55cb00ef9bdf00823c228f9830f32191585d972edc60c1ffa2e8060a958a1222
|
|
| MD5 |
f850e9581f9814e079e4db54c4e17715
|
|
| BLAKE2b-256 |
11a869031d97762985de0d55b078084f3622593678ba05081127d66a0b5d89fb
|
File details
Details for the file observicia-0.1.7-py3-none-any.whl.
File metadata
- Download URL: observicia-0.1.7-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
def98e5be6e7142d0bba60a4a9cdac7e67ddbb0359cc2ef96b0a968cfbebf160
|
|
| MD5 |
7cdbb11acf2aa927a6333a40a2825213
|
|
| BLAKE2b-256 |
1e4de9d2f90646cb857eb91ddd307e21599551d509179f5f062473dd9989aadd
|