Raindrop integration for LangChain
Project description
raindrop-langchain
Raindrop integration for LangChain (Python). Automatically captures LLM calls, tool usage, chains, and retrievers via LangChain's callback system.
Installation
pip install raindrop-langchain langchain-core
Quick Start
from raindrop_langchain import RaindropLangchain
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
raindrop = RaindropLangchain(
api_key="rk_...",
user_id="user-123",
)
model = ChatOpenAI(model="gpt-4o")
result = model.invoke(
[HumanMessage(content="Hello!")],
config={"callbacks": [raindrop.handler]},
)
raindrop.flush()
Factory Function (alternative)
from raindrop_langchain import create_raindrop_langchain
raindrop = create_raindrop_langchain(api_key="rk_...", user_id="user-123")
model = ChatOpenAI(model="gpt-4o")
result = model.invoke("Hello!", config={"callbacks": [raindrop.handler]})
raindrop.flush()
What Gets Captured
- LLM calls — model name, input, output, token usage, finish reason
- Tool calls — tool name, input arguments, output, duration (via
interaction.track_tool()spans) - Chains — execution tracking
- Retrievers — query and document count
- Errors — error type and message captured in event properties
- Extended token categories — cached tokens (
ai.usage.cached_tokens) and reasoning tokens (ai.usage.thoughts_tokens) when available from the provider (e.g. OpenAI) - Finish reason — captured as
ai.finish_reasonin event properties (e.g."stop","length")
Debug Mode
Enable verbose logging with debug=True:
raindrop = RaindropLangchain(
api_key="rk_...",
debug=True,
)
Identify Users
Associate events with a user after initialization:
raindrop.identify("user-123", {"name": "Alice", "plan": "pro"})
Track Signals
Send feedback, edits, or custom signals:
raindrop.track_signal(
event_id="evt-abc",
name="thumbs_up",
signal_type="feedback",
sentiment="POSITIVE",
)
Flushing and Shutdown
raindrop.flush() # flush pending data
raindrop.shutdown() # flush + release resources
API Reference
RaindropLangchain
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
Optional[str] |
None |
Raindrop API key. If None, telemetry is disabled |
user_id |
Optional[str] |
None |
Associate all events with a user |
convo_id |
Optional[str] |
None |
Group events into a conversation |
trace_chains |
bool |
True |
Track chain execution |
trace_retrievers |
bool |
True |
Track retriever calls |
filter_langgraph_internals |
bool |
True |
Filter LangGraph-internal chain events and deduplicate LLM callbacks |
tracing_enabled |
bool |
True |
Enable distributed tracing |
bypass_otel_for_tools |
bool |
True |
Bypass OTEL for tool spans |
debug |
bool |
False |
Enable debug logging |
Methods
| Method | Description |
|---|---|
handler |
Property — the LangChain callback handler to pass into config={"callbacks": [...]} |
flush() |
Flush all pending events to the Raindrop API |
shutdown() |
Flush remaining events and release resources |
identify(user_id, traits) |
Identify a user with optional traits |
track_signal(event_id, name, ...) |
Track a signal event |
Async Support
The callback handler inherits from LangChain's AsyncCallbackHandler and works with both synchronous and asynchronous LangChain invocations.
result = await model.ainvoke(
[HumanMessage(content="Hello!")],
config={"callbacks": [raindrop.handler]},
)
LangGraph Support
Works with LangGraph out of the box. The handler automatically filters LangGraph-internal chain events and deduplicates LLM callbacks. Pass the handler to the model inside your LLM node — not to graph.invoke(). See examples/langchain-langgraph-python-basic/ for a full example.
LangSmith Coexistence
Raindrop and LangSmith can run simultaneously. Set LANGSMITH_TRACING=false to disable LangSmith if you only want Raindrop.
Known Limitations
- Multi-LLM chain data: In ReAct loops with multiple child LLMs, only the last child's data survives (Python SDK uses one-shot
track_aivs TS's accumulativeEventShipper.patch). - Error-path input loss: On LLM errors, the input captured during
on_llm_startis not forwarded to the finalized event.
Testing
cd packages/langchain-python
pip install -e .
python -m pytest tests/ -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raindrop_langchain-0.0.3.tar.gz.
File metadata
- Download URL: raindrop_langchain-0.0.3.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab31fdd13b23f02e222e30e0f9936364cd76371f924bd87d06668770cf0cc1b9
|
|
| MD5 |
43cd1d0c8b3bab4142f72ba6ee7543a6
|
|
| BLAKE2b-256 |
682b76bf98837beb41b4f2726435650f024912258e00a2b344f7d79b812e84dd
|
File details
Details for the file raindrop_langchain-0.0.3-py3-none-any.whl.
File metadata
- Download URL: raindrop_langchain-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2096725f05e4494630c3357f0a83c904eb96e9ea516faa50ca13f118e54899a5
|
|
| MD5 |
f4de4d181050c6ba8a50572378fc9316
|
|
| BLAKE2b-256 |
a2075b801c463e1e3241e03cd4d0f5f9d419336ee1e036660c125c9b5004ea88
|