audr-adapter-langfuse
The AUDR span processor for Langfuse turns every generation,
embedding, tool and retriever observation recorded through the Langfuse Python SDK into one
AUDR record for an audr.Client your application owns. Because it
observes the Langfuse layer, one processor meters every integration that reports through
the SDK: the langfuse.openai drop-in, the LangChain CallbackHandler,
@observe(as_type="generation") and manual observations. It reads usage, cost,
identifiers and timings only: never observation input or output, prompts, completions or
error messages.
Status: alpha. The record model follows AUDR specification 1.x; until this package reaches 1.0.0, a minor release may change the public API.
Setup
pip install "audr-adapter-langfuse[runtime]"
Requires Python 3.11 or later and langfuse 5.2 or later within 5.x, which the runtime
extra installs. The Langfuse SDK is built on OpenTelemetry; the adapter is an OpenTelemetry
SpanProcessor added to the same TracerProvider as Langfuse's own processor. Langfuse and
OpenTelemetry are imported when LangfuseAudrProcessor is first accessed, not when
audr_adapter_langfuse is imported.
Usage
Construct the processor on the running event loop that owns the Client, add it to a
TracerProvider, and hand that provider to the Langfuse client:
import asyncio
from audr import Attribution, Client, FileSink
from audr_adapter_langfuse import LangfuseAudrProcessor, LangfuseConfig
from langfuse import Langfuse, propagate_attributes
from opentelemetry.sdk.trace import TracerProvider
async def main() -> None:
async with Client(FileSink("audr.jsonl")) as client:
processor = LangfuseAudrProcessor(
client=client,
config=LangfuseConfig(
provider="openai",
attribution_defaults=Attribution(environment="production"),
),
)
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(processor)
langfuse = Langfuse(tracer_provider=tracer_provider) # keys from LANGFUSE_* variables
try:
with propagate_attributes(metadata={"audr_account_id": "acct_42"}):
with langfuse.start_as_current_observation(
name="answer", as_type="generation", model="gpt-4o-mini"
) as generation:
generation.update(usage_details={"input": 120, "output": 40})
finally:
langfuse.shutdown()
await processor.drain(timeout=5)
processor.close()
asyncio.run(main())
Leaving the async with block drains the client's queue and closes its sink. A runnable
version that keeps Langfuse offline is
examples/observe_generation.py.
Attribution
Attribution is read for each span from audr_* metadata keys, field by field: observation
metadata wins over that of the observations still open around it, nearest first, which wins
over trace metadata set with propagate_attributes(), which wins over
langfuse.environment (only when it is exactly an AUDR environment), which wins over
LangfuseConfig.attribution_defaults. labels merge by key. Langfuse experiment runs
(sdk-experiment) are attributed to evaluation. Flat keys keep each value under
Langfuse's 200-character limit for propagated metadata:
from langfuse import propagate_attributes
with propagate_attributes(
metadata={
"audr_environment": "production",
"audr_account_id": "acct_42",
"audr_subscription_id": "sub_7",
"audr_user_id": "u_8f14e45f", # pseudonymous, never an email or a name
"audr_feature_id": "support-chat", # selects the meter the usage is billed against
"audr_labels": {"team": "support"},
}
):
pass # observations created here carry this attribution
- A span with no
environment, or aproductionspan with noaccount_id, is skipped with a warning rather than billed to a guess. - Langfuse's own
user_idis not copied toattribution.user_id: applications often put an email there. Setaudr_user_idto a pseudonymous id instead.
Records
| Langfuse observation type | resource.operation |
usage |
|---|---|---|
generation |
generation |
llm tokens, requests: 1 |
embedding |
embedding |
llm tokens, requests: 1 |
tool |
tool_execution |
tool, type: invocation, call_count: 1 |
retriever |
retrieval |
tool, type: retrieval, call_count: 1 |
Other types (span, agent, chain, event, evaluator, guardrail) and spans from
other OpenTelemetry instrumentation are not metered.
- Identifiers.
run.run_idandrun.trace_idare the OpenTelemetry trace id, andrun.span_idandrun.parent_span_idthe span ids, so every observation in one Langfuse trace joins. - Usage. Cache reads, cache writes and reasoning are counted apart from
input_tokensandoutput_tokens. Langfuse's exclusive buckets are folded back together, so audio and modality counts stay in input and output; raw OpenAI usage, as thelangfuse.openaidrop-in records it, and raw Anthropic usage are recognised too. The reference lists every key. - Cost. A generation's or embedding's
cost_detailsbecomescost.total_costin USD when the application or integration set it on the span. Langfuse's server-side inferred cost is never seen, so most records carry no cost. - Provider. Langfuse records no provider. The adapter takes
gen_ai.provider.name, thengen_ai.system, then the LangChainls_providermetadata, thenLangfuseConfig.provider. A generation or embedding with none is skipped with a warning. - Failures. A span with status
ERRORor levelERRORcarriesrun.error_code = LANGFUSE_OBSERVATION_ERROR. Failed tool and retriever spans are always recorded; a failed generation or embedding is recorded only when it reported usage or a positive cost.
When one model call is recorded as a model span inside another, as with LangChain's
ChatOpenAI while the langfuse.openai drop-in is imported, only the inner span is
recorded, with the audr_* metadata of the spans around it. Running this adapter alongside
another AUDR adapter that observes the same calls, such as the LiteLLM adapter, records each
call twice.
Documentation
- Reference: options, span metadata, record fields, shutdown order, diagnostics, operational bounds
- Examples: runnable offline, without Langfuse keys
- Changelog
- AUDR specification, which defines every record field
License
Apache-2.0. Contributions follow CONTRIBUTING.md.
Metadata
Release files for audr-adapter-langfuse 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| audr_adapter_langfuse-0.1.0.tar.gz | 18.7 kB | With provenance | Details for audr_adapter_langfuse-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| audr_adapter_langfuse-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for audr_adapter_langfuse-0.1.0-py3-none-any.whl |
Total release size: 40.6 kB
Release files / audr_adapter_langfuse-0.1.0.tar.gz
| Download URL | audr_adapter_langfuse-0.1.0.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
941c7d556d32f646aa5cfc13b886e2cdba0f0dab5ff06eeb20611a43d5af28cb
|
|
BLAKE2b-256 checksum How to use checksums |
e6fb5315b5f1e5692fa3ef43b1d7116703d12ac016d730091d456e0ada9af680
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / audr_adapter_langfuse-0.1.0-py3-none-any.whl
| Download URL | audr_adapter_langfuse-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d42b5468fbc741de1dc9a7b3f52ae7aea78c9763838d6ad2d7009239aeb48546
|
|
BLAKE2b-256 checksum How to use checksums |
636ae5dc2fb166b5a172c3e3ff680f917119ed2facce2f22952bb83acf439890
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for audr-adapter-langfuse 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for audr_adapter_langfuse-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.