Skip to main content

Raindrop observability integration for DSPy

Project description

raindrop-dspy

PyPI version Python License: MIT

Raindrop observability integration for DSPy. Wraps DSPy modules (Predict, ChainOfThought, etc.) to automatically capture input fields, output fields, model name, and token usage.

Installation

pip install raindrop-dspy dspy

Quick Start

import dspy
from raindrop_dspy import RaindropDSPy

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

lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)

predict = dspy.Predict("question -> answer")
wrapped = raindrop.wrap(predict)

result = wrapped(question="What is the capital of France?")
print(result.answer)

raindrop.shutdown()

Debug Mode

Enable verbose logging to troubleshoot issues:

raindrop = RaindropDSPy(api_key="rk_...", debug=True)

Factory Function (Legacy)

The create_raindrop_dspy factory function is still available for backwards compatibility:

from raindrop_dspy import create_raindrop_dspy

raindrop = create_raindrop_dspy(
    api_key="rk_...",
    user_id="user-123",
    tracing_enabled=True,
    bypass_otel_for_tools=True,
)
wrapped = raindrop.wrap(predict)

What Gets Captured

Data Description
Input fields All keyword arguments passed to forward()
Output fields Extracted from the DSPy Prediction result
Model name From the active dspy.settings.lm configuration
Token usage Prompt and completion tokens (when available)
Errors Exception type and message captured in event properties
Finish reason Completion finish reason (e.g. stop, length) from the LM history

API Reference

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

Create a new Raindrop DSPy integration instance.

Parameter Type Default Description
api_key str | None None Raindrop API key. If omitted, 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 OpenTelemetry tracing
bypass_otel_for_tools bool True Bypass OTEL instrumentation for tool calls
disable_auto_instrument bool True Library auto-instrumentation is opt-in (see below)
debug bool False Enable debug logging (sets logger to DEBUG level)

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 (including the OpenAI client DSPy drives through LiteLLM). The wrapper captures input/output, token usage, and model name directly from the wrapped module's forward() calls and DSPy LM history, 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.

Methods

Method Description
wrap(module) Instrument a DSPy module (sync and async forward supported)
flush() Flush buffered 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 signal on an AI event (e.g. thumbs up/down, feedback)

Identifying Users

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

Tracking Signals

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

Flushing and Shutdown

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

Async Support

DSPy modules with async forward methods are automatically detected and wrapped:

import dspy
from raindrop_dspy import RaindropDSPy

raindrop = RaindropDSPy(api_key="rk_...")

class AsyncPredict(dspy.Module):
    async def forward(self, question: str) -> dspy.Prediction:
        ...

wrapped = raindrop.wrap(AsyncPredict())
result = await wrapped(question="Hello")

Double-Wrap Protection

Calling wrap() on an already-wrapped module is a no-op — the module is returned unchanged.

Development

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

License

MIT

Full documentation

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_dspy-0.0.5.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

raindrop_dspy-0.0.5-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file raindrop_dspy-0.0.5.tar.gz.

File metadata

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

File hashes

Hashes for raindrop_dspy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dc1c3f76f295e1a75c1baf67d39e3539c62383316834575e522a100511390c2f
MD5 8fcd949ef5ecd061e1dcd8f98f46908e
BLAKE2b-256 8cddabf2ee23afd173052944194443638d024b48cd6f3fb313f747a6e5c17dcb

See more details on using hashes here.

File details

Details for the file raindrop_dspy-0.0.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for raindrop_dspy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c2cd5a18888c907723dfd04bc29d0d0bd019b60f0fe5008cea00e702b99f726d
MD5 63742f6a3983d8ea0f64a31a428e8733
BLAKE2b-256 f5ae4765e6400e98b0b3e6138685749c885fa0ec919ac8a416c0c9eb66140a0c

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