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.3.tar.gz (13.9 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.3-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8d631216196c0f81dfe204e061264130e3014af5c7084bc789b112daea179142
MD5 befeeecaa80ba16f7761eaa49e015399
BLAKE2b-256 8b15b0032bc7711e3d592f67ae4b4b2c5b3a637fcf3f2c78c78f229371922ccd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 66caf0f1be047fd68b2a063d27e637e99c8829530528af3ee647e6bbfd8a2f4c
MD5 ba54cd9e349bf8b4a5ec87b5a4b66abb
BLAKE2b-256 b478284629a71a5dabc8cd26ca7929e45f912f801fb28e92a68fcc56f4cdc9a1

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