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.1.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.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ce55bda6a9416a7022451ea025c7596324a4b741dcf5114aefff8fbd3cf0fe93
MD5 69b1bb6737e43355c5e5716946b2ba49
BLAKE2b-256 7848e2bfeb438389795e77548553f606c63ddf5f60ed636f76a429bce027404d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rabbittwatch_ai_observability-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96a4e031b9785c551093d57d3606f9747f40d1680ebfd809140bea9a35c0b80c
MD5 647f1fd634d9cb13e7f8c43c6da15ede
BLAKE2b-256 67d2474a3345692911f001c09e0ee9a98918a529be55cec2bcde8149f0fba49d

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