Env-only Langfuse tracing adapter for LangChain/LangGraph; callback handler as primary integration.
Project description
langfuse-tracing-adapter
Env-only Langfuse tracing adapter for LangChain/LangGraph. Callback handler is the primary integration; no @observe decorator required.
Install
pip install langfuse-tracing-adapter langfuse
Env
Set before running your app:
LANGFUSE_BASE_URL— Langfuse server URL (e.g.http://localhost:3011)LANGFUSE_PUBLIC_KEY— Project public key (from Langfuse UI)LANGFUSE_SECRET_KEY— Project secret keyLANGFUSE_PROJECT— Project name (optional, default"default")
Usage
- Startup:
init_client()once (e.g. FastAPI lifespan). - LLM runs: Pass
get_callback_handler()in config:config["callbacks"] = [get_callback_handler()]. - Optional:
run_metadata_for_org(org_id, extra_tags=..., custom_metadata=...)in config for org isolation and custom metadata. - After run:
get_context().update_current_trace(input=..., output=..., metadata=...)thenflush(). - Shutdown:
flush()thenshutdown().
Using the adapter in another project
- Install:
pip install langfuse-tracing-adapter langfuse - Env: Set
LANGFUSE_BASE_URL,LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY,LANGFUSE_PROJECT(optional). - Startup: Call
init_client()once (e.g. FastAPI lifespan, DjangoAppConfig.ready, or main). - LLM entry points: Pass
get_callback_handler()into LangChain/LangGraph config (e.g.config["callbacks"] = [get_callback_handler()]when not None). One trace per run; no observe decorator required. - Optional: Use
run_metadata_for_org(org_id, extra_tags=..., custom_metadata=...)in config for org isolation and custom metadata. After the run, callget_context().update_current_trace(input=..., output=..., metadata=...). - After request / shutdown: Call
flush()so traces are sent; on shutdown callshutdown().
Publishing to PyPI
The package is universal (env-only; use in any project). To publish so others can pip install langfuse-tracing-adapter:
- Prerequisites: PyPI account, API token (PyPI → Account settings → API tokens), and
pip install build twine. - Bump version in
pyproject.toml(e.g.0.1.0→0.1.1). - Build: From repo root:
python -m build langfuse_tracing_adapter/— or from this dir:python -m build. - Upload:
cd langfuse_tracing_adapter && twine upload dist/*(useTWINE_USERNAME=__token__,TWINE_PASSWORD=<pypi-token>). Test first withtwine upload --repository testpypi dist/*.
Full step-by-step: see PUBLISH_TO_PYPI.md in this directory.
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 langfuse_tracing_adapter-0.1.1.tar.gz.
File metadata
- Download URL: langfuse_tracing_adapter-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55857d790ac456b9d32aa3977ed795a81496730948330696144e8987be81c6b2
|
|
| MD5 |
164d9398d68895caacfb860133b10522
|
|
| BLAKE2b-256 |
273d606b3b586f85092075b053d5e3852351b47560861e8302a7a39f02508492
|
File details
Details for the file langfuse_tracing_adapter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langfuse_tracing_adapter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bd41719e913d3d067e13925887363936a5ad6e1db4b083426dc8237db52764c
|
|
| MD5 |
eeb5c7d547025a0f81e92fc2f9241ef9
|
|
| BLAKE2b-256 |
e96584f6fabbcf1c326518617dfff7905b28eeb10378779cea3459c2c402dbd0
|