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.4.tar.gz (22.3 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.4-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raindrop_dspy-0.0.4.tar.gz
  • Upload date:
  • Size: 22.3 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.4.tar.gz
Algorithm Hash digest
SHA256 fca51f124a4acbde140c0b34f0df9525b9cd56f485f49ec28a2a87e4ca123e1c
MD5 30d23f9288c2694859b56f633370fcd6
BLAKE2b-256 3d7efe2ecf1318f9efe1f7b8d803e5372d958ec6a895d48396bc5b0b86f28bbf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raindrop_dspy-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ac32c4780b4e53b9a99c11c9f032408510f2d8201b572d763005392a1290d3ad
MD5 f5f3e140e95c8519b0bf0a307ddd8952
BLAKE2b-256 b6e361c638643cdbde630ac9fb52eb02fe1a051a807d170cd44252bbef9b44cb

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