Local tracing hooks for LangChain and LangGraph
Project description
slimchain
Local tracing hooks for LangChain and LangGraph. Stores traces locally or posts them to a webhook.
Install
pip install -e .
Enable tracing
Tracing is controlled by SLIMCHAIN_TRACING and an output directory:
SLIMCHAIN_TRACING=trueto enable recording.SLIMCHAIN_DIR=/path/to/outputto control where JSON is written (default:~/.slimchain).
Traces are written to:
traces.jsonl(append-only)traces.json(pretty JSON)
Webhook ingestion
To post traces to slimchain servers, set the webhook endpoint and project id:
SLIMCHAIN_ENDPOINT=https://your-serverSLIMCHAIN_PROJECT_ID=123SLIMCHAIN_API_KEY=your_project_api_key
When SLIMCHAIN_ENDPOINT and SLIMCHAIN_PROJECT_ID are set, traces are POSTed to:
POST {SLIMCHAIN_ENDPOINT}/traces/{SLIMCHAIN_PROJECT_ID}
.env support
If a .env file exists in the working directory, slimchain will load it on startup.
You can override the path with SLIMCHAIN_DOTENV=/path/to/.env.
LangChain integration
Attach the callback to any LangChain model or runnable:
from slimchain.client import Client
from slimchain.watcher import SlimchainCallback
client = Client(root=".slimchain")
client.config.tracing = True
callback = SlimchainCallback(client=client)
# Example with any LangChain chat model
model = SomeChatModel(
model="...",
callbacks=[callback],
)
response = model.invoke("Say hello in one sentence.")
LangGraph integration
Pass the callback via the LangGraph node or runnable config:
from slimchain.client import Client
from slimchain.watcher import SlimchainCallback
from langgraph.graph import END, StateGraph
client = Client(root=".slimchain")
client.config.tracing = True
callback = SlimchainCallback(client=client)
# inside a node function
message = model.invoke(prompt, config={"callbacks": [callback]})
Examples
Run the smoke examples after installing their dependencies:
pip install langchain-openai langchain-google-genai langgraph
Gemini:
SLIMCHAIN_TRACING=true \
GOOGLE_API_KEY=... \
.venv/bin/python examples/gemini_smoke.py
OpenRouter (OpenAI-compatible client):
SLIMCHAIN_TRACING=true \
OPENROUTER_API_KEY=... \
.venv/bin/python examples/openrouter_smoke.py
LangGraph (OpenRouter):
SLIMCHAIN_TRACING=true \
OPENROUTER_API_KEY=... \
.venv/bin/python examples/langgraph_smoke.py
Multi-agent (Gemini + OpenRouter):
SLIMCHAIN_TRACING=true \
GOOGLE_API_KEY=... \
OPENROUTER_API_KEY=... \
.venv/bin/python examples/multi_agent_smoke.py
Optional model overrides for the multi-agent example:
GEMINI_MODEL=gemini-3.1-flash-lite
OPENROUTER_MODEL=openai/gpt-4o-mini
Output schema
Each trace record includes:
trace_id,node_name,frameworkinput,outputtokens_in,tokens_outduration_ms,model_usedtimestamp,project,status,errormetadata
TEST
.venv/bin/python -m pytest -q
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 slimchain-0.1.1.tar.gz.
File metadata
- Download URL: slimchain-0.1.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30a3258442806eda0d54a86ddfe3d05951cc40c980ea038f91ba8f268f36a677
|
|
| MD5 |
846c3e5cc7ac360fa1bb3379cd74e1b1
|
|
| BLAKE2b-256 |
0a5cace82edf5e2d7a744f9e1e193c21616015204707f10e285fc8c6eb3a51a0
|
File details
Details for the file slimchain-0.1.1-py3-none-any.whl.
File metadata
- Download URL: slimchain-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba203cf9aebf7bc204fa0d48371fe876f24506c9573f69bca9330f7e1a86a70
|
|
| MD5 |
3b9f0cfa2b6d3722b91ccd78940adcdb
|
|
| BLAKE2b-256 |
f60cef0efafb02f326f1cf89c7e20e53ff90f66c36dc69abdb7302d88cd76e38
|