Skip to main content

RabbittWatch AI Observability tracing SDK for Python

Project description

RabbittWatch AI Observability Python SDK

A lightweight Python SDK to track LLM costs, tokens, latencies, error states, and distributed traces in RabbittWatch.

Installation

pip install .

Basic Usage

from rabbittwatch.client import RabbittWatchAI

rw_ai = RabbittWatchAI(
    api_key="rw_live_xxxxx",
    environment="prod",
    service_name="customer-support"
)

# Wrapping a call
response = rw_ai.trace(
    name="agent.answer",
    provider="openai",
    model="gpt-4o",
    input="Hello!",
    fn=lambda: openai_client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}]
    )
)

Trace Context Manager & Decorators

You can trace code using context managers:

with rw_ai.trace("manual.step", provider="openai", model="gpt-4o") as trace:
    # Run code...
    trace.spans[0].end(output="Processed result")

Or using python decorators:

@rw_ai.trace_decorator(name="llm_agent_kickoff")
def kickoff_agent(task_description):
    # Agent logic...
    return {"output": "Completed task"}

Security & Advanced Sanitization

Configure recursive object redaction and custom scrubbers:

import re

rw_ai = RabbittWatchAI(
    api_key="rw_live_xxxxx",
    captureInput=True,
    captureOutput=True,
    
    # Custom regex compilation rules
    redactPatterns=[re.compile(r"custom-key-\d+", re.IGNORECASE)],
    # Custom sanitization lambda/function
    customRedactFn=lambda text: text.replace("confidential-info", "[scrubbed]")
)

Lifecycle Plugins System

Create and register custom plugins to inspect or pipe telemetry:

from rabbittwatch import RabbittWatchPlugin

class CustomMetricsPlugin(RabbittWatchPlugin):
    def __init__(self):
        super().__init__("CustomMetricsPlugin")
        
    def on_span_end(self, span, options: dict) -> None:
        print(f"Span ended: {span.span_id}")

rw_ai.register_plugin(CustomMetricsPlugin())

Context Propagation (OpenCode & Microservices)

Share trace context over HTTP or event boundaries (captures x-opencode-session-id, x-rabbittize-trace-id, etc.):

# Service A: Inject headers
trace = rw_ai.start_trace("parent-trace", metadata={"sessionId": "opencode-session-xyz"})
span = trace.start_span({"name": "sub-step"})

headers = {}
headers = rw_ai.inject_headers(headers, span)

# Service B: Extract headers
extracted = rw_ai.extract_headers(received_headers)
sub_trace = rw_ai.start_trace("child-trace", **extracted)

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

rabbittwatch_ai_observability-0.1.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

rabbittwatch_ai_observability-0.1.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file rabbittwatch_ai_observability-0.1.2.tar.gz.

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.2.tar.gz
Algorithm Hash digest
SHA256 97c9d7c0b2014bbea11d42a7d356938118c723094c191c9bde0911ecd74da328
MD5 8c21a08611f29424cdd9b2dcd0204b33
BLAKE2b-256 056764628fa94127938fdaf5e4c133eedd04ce4a4fdb4f2c65b8250723644c4a

See more details on using hashes here.

File details

Details for the file rabbittwatch_ai_observability-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c21aa5561722a0b6ae29e405bf327ee02906aa1fee520ff1774821391aa1bea
MD5 26679bae64111c1e403dbe3a38965733
BLAKE2b-256 f2a5ed8359d06ec1a3df6afe420286fd4e3800f40b8e62b7861aa73fe250cfaf

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