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.0.tar.gz (4.0 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.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for langfuse_tracing_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 546561758301f6e91b2a7a6a9232a99f5fb4f04d6388c078fc71e2ec77afc555
MD5 96a3bda17c79df7907d23f84ac4cdf95
BLAKE2b-256 266b8900a1a9b4902f8c805d60de33bc3f4a7cf6cd7949abe85a9d28048e138b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langfuse_tracing_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12796a663dedf92af85ccb12918478d5bf55b8ff1c721aa8f245cb3b1b2196b2
MD5 c0cb6a4cbee7d0f2712b111c5c6f8f1b
BLAKE2b-256 a4bca843e4a154f8f550d6665cfc40aef7530b363661fcac325e5c0f53032267

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