Skip to main content

Raindrop integration for Pydantic AI — automatic observability for Agent run() and run_sync() calls

Project description

raindrop-pydantic-ai

Raindrop integration for Pydantic AI. Automatically captures Agent run() and run_sync() calls including input, output, model name, token usage, and finish reason.

PyPI version Python versions License: MIT

Installation

pip install raindrop-pydantic-ai pydantic-ai

Quick Start

from raindrop_pydantic_ai import RaindropPydanticAI
from pydantic_ai import Agent

raindrop = RaindropPydanticAI(
    api_key="your-write-key",
    user_id="user-123",
)

agent = Agent("openai:gpt-4o", system_prompt="Be helpful")
raindrop.wrap(agent)

result = agent.run_sync("What is the capital of France?")
print(result.output)

raindrop.flush()

Async Usage

import asyncio
from raindrop_pydantic_ai import RaindropPydanticAI
from pydantic_ai import Agent

raindrop = RaindropPydanticAI(api_key="rk_...", user_id="user-123")
agent = Agent("openai:gpt-4o")
raindrop.wrap(agent)

async def main():
    result = await agent.run("What is the capital of France?")
    print(result.output)
    raindrop.flush()

asyncio.run(main())

Factory Function (Legacy)

The create_raindrop_pydantic_ai() factory function is still available for backwards compatibility:

from raindrop_pydantic_ai import create_raindrop_pydantic_ai

raindrop = create_raindrop_pydantic_ai(api_key="rk_...", user_id="user-123")

What Gets Captured

  • Agent runs: input prompt, output text (including structured output), model name
  • Token usage: input_tokens and output_tokens from the result
  • Finish reason: pydantic_ai.finish_reason captured from the last model response (e.g. "stop", "length", "tool_call")
  • Errors: error type and message captured in event properties, then re-raised
  • Async support: both run() (async) and run_sync() (sync) are instrumented
  • Double-wrap guard: calling wrap() twice on the same agent is a safe no-op

API Reference

RaindropPydanticAI(api_key, user_id=None, convo_id=None, tracing_enabled=True, bypass_otel_for_tools=True, disable_auto_instrument=True, debug=False)

Create a new Raindrop wrapper instance.

Parameter Type Default Description
api_key str | None None Raindrop API key. When None or empty, telemetry is disabled
user_id str | None None Associate all events with a user
convo_id str | None None Group events into a conversation
tracing_enabled bool True Enable/disable tracing in raindrop.init()
bypass_otel_for_tools bool True Bypass OpenTelemetry for tool calls
disable_auto_instrument bool True Library auto-instrumentation is opt-in (see below)
debug bool False Enable DEBUG-level logging for the package

Library auto-instrumentation is opt-in

As of 0.0.4, disable_auto_instrument defaults to True: the integration no longer lets Traceloop monkey-patch every LLM client library it recognizes in your process (OpenAI, Anthropic, botocore, google-genai, etc.). The wrapper captures input/output, token usage, model name, and finish_reason directly from run() / run_sync() results, so no library patching is needed for full dashboards.

If you specifically want LLM-call-level spans from library instrumentation and have verified compatibility in your environment, opt back in with disable_auto_instrument=False.

Debug Mode

raindrop = RaindropPydanticAI(
    api_key="rk_...",
    debug=True,  # enables DEBUG-level logging
)

identify(user_id, traits=None)

Identify a user with optional traits:

raindrop.identify("user-123", traits={"name": "Alice", "plan": "pro", "age": 30})

track_signal(event_id, name, signal_type="default", ...)

Track a signal event (feedback, edits, etc.):

raindrop.track_signal(
    event_id="evt-abc",
    name="thumbs_up",
    signal_type="feedback",
    sentiment="POSITIVE",
    comment="Great answer!",
)

flush() / shutdown()

Flush pending events before your process exits:

raindrop.flush()     # flush pending data
raindrop.shutdown()  # flush + release resources

Methods

Method Description
wrap(agent) Instrument a Pydantic AI Agent
flush() Flush pending events to Raindrop
shutdown() Flush and shut down the client
identify(user_id, traits=None) Identify a user with optional traits
track_signal(event_id, name, signal_type="default", ...) Track a custom signal event

Testing

cd packages/pydantic-ai-python
pip install -e ".[dev]"
python -m pytest tests/ -v

Full Documentation

See Raindrop Pydantic AI Integration Docs for full documentation.

License

MIT

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

raindrop_pydantic_ai-0.0.4.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

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

raindrop_pydantic_ai-0.0.4-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file raindrop_pydantic_ai-0.0.4.tar.gz.

File metadata

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

File hashes

Hashes for raindrop_pydantic_ai-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7f19af07cd4597a9fdf215e76a06ff085626bad0c7bb5714681cb66a19d5b380
MD5 c4c04c7534effb549176beba6beb5536
BLAKE2b-256 c3e9ef77bdeff74d9f7714c06cd989a42d5eda8c9921285325973a3c9b32aad3

See more details on using hashes here.

File details

Details for the file raindrop_pydantic_ai-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for raindrop_pydantic_ai-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7f2b07117a9658d6d7a3939a3e93a5714c6f43ff4126b5a51d93e2b2ea147d
MD5 82487d055fd5e439a218ea3717f6b308
BLAKE2b-256 3899d0ad63087d81dc7d94ebf7a55f6f9b9f02e126dc6ac4a8de3f60b2789b56

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