Skip to main content

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.

License OpenTelemetry OPA

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
  • 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

  1. Install the SDK:
pip install observicia
  1. Create a configuration file (observicia_config.yaml):
service_name: my-llm-app
otel_endpoint: http://otel-collector:4317
opa_endpoint: http://opa:8181
policies:
  - name: pii_check
    path: observicia/pii
    description: Check for PII in responses
    required_trace_level: enhanced
    risk_level: high
log_file: app.log
trace_console: true
  1. 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:

  1. Simple Chat Application (examples/simple-chat)

    • Basic chat interface using OpenAI
    • Demonstrates token tracking and tracing
    • Shows streaming response handling
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

observicia-0.1.5.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

observicia-0.1.5-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file observicia-0.1.5.tar.gz.

File metadata

  • Download URL: observicia-0.1.5.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for observicia-0.1.5.tar.gz
Algorithm Hash digest
SHA256 48c92d3fab18c5bb9e7327e1e90c66d24e068010b887ebb3c6e9795b6e715794
MD5 b40d1b94f336566be6db846a454a57fe
BLAKE2b-256 1506e8ed14614104de0db1d701665ae23042238ce4345fb4126999d2dc0626c5

See more details on using hashes here.

File details

Details for the file observicia-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: observicia-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for observicia-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 14f17b4201dd437cfa1f642dd41707f4328961cb8309df8a7da21c71ec115d4c
MD5 0c559330f26c533bffefaced36ccea75
BLAKE2b-256 071f279fe7464073119bddc3b3a15310592455dec584ec6775f15d316aace56c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page