Skip to main content

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 key
  • LANGFUSE_PROJECT — Project name (optional, default "default")

Usage

  1. Startup: init_client() once (e.g. FastAPI lifespan).
  2. LLM runs: Pass get_callback_handler() in config: config["callbacks"] = [get_callback_handler()].
  3. Optional: run_metadata_for_org(org_id, extra_tags=..., custom_metadata=...) in config for org isolation and custom metadata.
  4. After run: get_context().update_current_trace(input=..., output=..., metadata=...) then flush().
  5. Shutdown: flush() then shutdown().

Using the adapter in another project

  1. Install: pip install langfuse-tracing-adapter langfuse
  2. Env: Set LANGFUSE_BASE_URL, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_PROJECT (optional).
  3. Startup: Call init_client() once (e.g. FastAPI lifespan, Django AppConfig.ready, or main).
  4. 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.
  5. Optional: Use run_metadata_for_org(org_id, extra_tags=..., custom_metadata=...) in config for org isolation and custom metadata. After the run, call get_context().update_current_trace(input=..., output=..., metadata=...).
  6. After request / shutdown: Call flush() so traces are sent; on shutdown call shutdown().

Publishing to PyPI

The package is universal (env-only; use in any project). To publish so others can pip install langfuse-tracing-adapter:

  1. Prerequisites: PyPI account, API token (PyPI → Account settings → API tokens), and pip install build twine.
  2. Bump version in pyproject.toml (e.g. 0.1.00.1.1).
  3. Build: From repo root: python -m build langfuse_tracing_adapter/ — or from this dir: python -m build.
  4. Upload: cd langfuse_tracing_adapter && twine upload dist/* (use TWINE_USERNAME=__token__, TWINE_PASSWORD=<pypi-token>). Test first with twine upload --repository testpypi dist/*.

Full step-by-step: see PUBLISH_TO_PYPI.md in this directory.

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

langfuse_tracing_adapter-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

langfuse_tracing_adapter-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file langfuse_tracing_adapter-0.1.1.tar.gz.

File metadata

File hashes

Hashes for langfuse_tracing_adapter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55857d790ac456b9d32aa3977ed795a81496730948330696144e8987be81c6b2
MD5 164d9398d68895caacfb860133b10522
BLAKE2b-256 273d606b3b586f85092075b053d5e3852351b47560861e8302a7a39f02508492

See more details on using hashes here.

File details

Details for the file langfuse_tracing_adapter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langfuse_tracing_adapter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3bd41719e913d3d067e13925887363936a5ad6e1db4b083426dc8237db52764c
MD5 eeb5c7d547025a0f81e92fc2f9241ef9
BLAKE2b-256 e96584f6fabbcf1c326518617dfff7905b28eeb10378779cea3459c2c402dbd0

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