Skip to main content

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=true to enable recording.
  • SLIMCHAIN_DIR=/path/to/output to 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-server
  • SLIMCHAIN_PROJECT_ID=123
  • SLIMCHAIN_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, framework
  • input, output
  • tokens_in, tokens_out
  • duration_ms, model_used
  • timestamp, project, status, error
  • metadata

TEST

.venv/bin/python -m pytest -q

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

slimchain-0.1.1rc1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

slimchain-0.1.1rc1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file slimchain-0.1.1rc1.tar.gz.

File metadata

  • Download URL: slimchain-0.1.1rc1.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

Hashes for slimchain-0.1.1rc1.tar.gz
Algorithm Hash digest
SHA256 1b4a665e71f8e22fc8a1435df97da00f1a31b1c1b93c33bec39c6476c0e2ff21
MD5 495d7ccc143207a0514b54701053eb38
BLAKE2b-256 cac4657258570a975365fe994e3ce1916558f65349aca2131515c5e56dfd5d0c

See more details on using hashes here.

File details

Details for the file slimchain-0.1.1rc1-py3-none-any.whl.

File metadata

  • Download URL: slimchain-0.1.1rc1-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

Hashes for slimchain-0.1.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 d363da1d6cc66aa0f3b32960b5ecf45e2f336fb59e4736769705b5d80c0cbb98
MD5 0d7815609a102403deb232b3e48f9ed9
BLAKE2b-256 fea71015d53279ffb1cd580152d2570b43611ebb631c63a374cf7a3f4411b181

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