Skip to main content

Minimal, extensible LLM observability SDK with OpenAI and Gemini support.

Project description

aiobs

A tiny, extensible observability layer for LLM calls. Add three lines around your code and get JSON traces for requests, responses, timings, and errors.

Supported Providers

  • OpenAI — Chat Completions API (openai>=1.0)
  • Google Gemini — Generate Content API (google-genai>=1.0)

Quick Install

# Core only
pip install aiobs

# With OpenAI support
pip install aiobs[openai]

# With Gemini support
pip install aiobs[gemini]

# With all providers
pip install aiobs[all]

Quick Start

from aiobs import observer

observer.observe()    # start a session and auto-instrument providers
# ... make your LLM calls (OpenAI, Gemini, etc.) ...
observer.end()        # end the session
observer.flush()      # write a single JSON file to disk

By default, events flush to ./llm_observability.json. Override with LLM_OBS_OUT=/path/to/file.json.

Provider Examples

OpenAI

from aiobs import observer
from openai import OpenAI

observer.observe()

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}]
)

observer.end()
observer.flush()

Google Gemini

from aiobs import observer
from google import genai

observer.observe()

client = genai.Client()
response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="Hello!"
)

observer.end()
observer.flush()

Function Tracing with @observe

Trace any function (sync or async) by decorating it with @observe:

from aiobs import observer, observe

@observe
def research(query: str) -> list:
    # your logic here
    return results

@observe(name="custom_name")
async def fetch_data(url: str) -> dict:
    # async logic here
    return data

observer.observe(session_name="my-pipeline")
research("What is an API?")
observer.end()
observer.flush()

Decorator Options

Option Default Description
name function name Custom display name for the traced function
capture_args True Whether to capture function arguments
capture_result True Whether to capture the return value
# Don't capture sensitive arguments
@observe(capture_args=False)
def login(username: str, password: str):
    ...

# Don't capture large return values
@observe(capture_result=False)
def get_large_dataset():
    ...

What Gets Captured

For each decorated function call:

  • Function name and module
  • Input arguments (args/kwargs)
  • Return value
  • Timing: start/end timestamps, duration_ms
  • Errors: exception name and message if the call fails
  • Callsite: file path, line number where the function was defined

Run the Examples

  • Simple OpenAI example:

    python example/simple-chat-completion/chat.py
    
  • Gemini example:

    python example/gemini/main.py
    
  • Multi-file pipeline example:

    python -m example.pipeline.main "Explain vector databases to a backend engineer"
    

What Gets Captured (LLM Calls)

  • Provider: openai or gemini
  • API: e.g., chat.completions or models.generateContent
  • Request: model, messages/contents, core parameters
  • Response: text, model, token usage (when available)
  • Timing: start/end timestamps, duration_ms
  • Errors: exception name and message if the call fails
  • Callsite: file path, line number, and function name where the API was called

Data Models

Internally, the SDK structures data with Pydantic models (v2):

  • aiobs.Session – Session metadata
  • aiobs.Event – LLM provider call event
  • aiobs.FunctionEvent – Decorated function trace event
  • aiobs.ObservedEvent (Event + session_id)
  • aiobs.ObservedFunctionEvent (FunctionEvent + session_id)
  • aiobs.ObservabilityExport (flush payload)

These are exported to allow downstream tooling to parse and validate the JSON output and to build integrations.

Extensibility

Providers are classes that implement a small abstract interface and install their own hooks.

  • Base class: aiobs.BaseProvider
  • Built-in: OpenAIProvider, GeminiProvider (auto-detected and installed if available)

Custom provider skeleton:

from aiobs import BaseProvider, observer

class MyProvider(BaseProvider):
    name = "my-provider"

    @classmethod
    def is_available(cls) -> bool:
        try:
            import my_sdk  # noqa: F401
            return True
        except Exception:
            return False

    def install(self, collector):
        # monkeypatch or add hooks into your SDK, then
        # call collector._record_event({ ... normalized payload ... })
        def unpatch():
            pass
        return unpatch

# Register before observe()
observer.register_provider(MyProvider())
observer.observe()

Architecture

  • Core
    • Collector holds sessions/events and flushes a single JSON file.
    • aiobs.models.* define Pydantic schemas for sessions/events/export.
  • Providers (N-layered)
    • providers/base.py: BaseProvider interface.
    • providers/openai/: OpenAI Chat Completions instrumentation.
    • providers/gemini/: Google Gemini Generate Content instrumentation.

Providers construct Pydantic request/response models and pass typed Event objects to the collector; only the collector serializes to JSON.

Docs

Sphinx documentation lives under docs/.

  • Install docs deps:
    pip install aiobs[docs]
    
  • Build HTML docs:
    python -m sphinx -b html docs docs/_build/html
    
  • Open docs/_build/html/index.html in your browser.

GitHub Pages

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

aiobs-0.1.1.tar.gz (105.8 kB view details)

Uploaded Source

Built Distribution

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

aiobs-0.1.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file aiobs-0.1.1.tar.gz.

File metadata

  • Download URL: aiobs-0.1.1.tar.gz
  • Upload date:
  • Size: 105.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiobs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 246f444dfc41a40662f9518cd3cfcd7ca6e48205a099c9b0b7fb90b565895c22
MD5 d2bb13709d0f9ca1fd9efbebc44815bd
BLAKE2b-256 42c0a2738d467fef98b62144be1199e7c63ba5975f5ac5d1edef67275795b03b

See more details on using hashes here.

File details

Details for the file aiobs-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: aiobs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiobs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94f9df21d43aa7eda0522e8853c29abf25477e1d1fe0c832d0aa522f3735c7e0
MD5 68a52c1a2c8d804d7f63ed85007a3d90
BLAKE2b-256 a15ee8154c01c8da8b134da391bac16f7e4497fe1128d73fc4180b5f34b188f8

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