What this thread does
Do first: configure LANGFUSE_BASE_URL for the intended region and disable decorator payload capture before instrumenting the first agent request.
Short answer
As of November 2026, this recipe uses Python SDK 5.0.0, requiring Python 3.11+ and self-hosted server 4.59.0+ or Cloud. Record actual operation spans and provider usage.
Choose / don't choose
- Native provider instrumentation: choose for supported usage normalization; don't enable prompt/tool payload capture before defining a privacy policy.
- Manual observations: choose for custom providers; don't record a completed model response inside a newly opened generation and expect useful latency.
- Environments: choose labels for filtering within a project.
Not for: Claude Code session hooks; see langfuse-trace-claude-code-sessions-stop-hook-plugin.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
LANGFUSE_BASE_URL, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY | Regional/deployment URL plus credentials from that project; configure through secret management | Current Python SDK setup | overview |
LANGFUSE_TRACING_ENVIRONMENT / environment | Explicit environment label; default default; constructor wins over environment variable | Current SDK | environment |
capture_input, capture_output | Set both False on observe to omit automatic decorator IO | Current Python SDK | instrumentation |
mask_otel_spans | Export-stage callback removes sensitive raw span attributes, including third-party spans; keep it fast | Current Python SDK | masking |
as_type | Parent span, model generation; nested tool tool observations surround actual work | Current Python SDK | observation types |
model, usage_details, cost_details | Actual model name plus provider counts in exclusive usage buckets; ingest USD cost directly or infer it via a model definition | Current SDK | usage |
sample_rate | Default 1; permitted range 0–1; 0.2 collects about 20% of traces | Current SDK | sampling |
flush_at, flush_interval | Defaults 512 spans / 5 seconds | Current Python batching | defaults |
Order of operations
1. Check server/SDK compatibility and intended project/region. Initialize privacy controls before provider wrappers. Environment tags organize data; they do not establish project authorization. 2. Keep the parent agent observation current while tool and generation children run. Carry OpenTelemetry context across async/thread/service boundaries; ensure parent spans are exported too (context and filtering, advanced propagation). 3. Wrap the entire provider call, including stream consumption, in the generation. Populate provider usage; input and output exclude separately counted cached/reasoning buckets, while total is their sum. Langfuse no longer estimates missing token counts from text (usage). 4. End tools, then model/agent parents when their operations complete; call langfuse.flush() before a short-lived process returns. 5. Compare instrumentation overhead and event counts against the same workload without instrumentation. Reduce trace sampling or adjust batching, then remeasure; a sample rate is not a latency guarantee.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Tool appears at trace root (symptom) | Missing active context or parent never exported | Use current-observation context managers, propagate context, inspect filtered scopes, export parent | nesting |
| Missing usage / misleading latency (symptom) | Instrument the call itself; map provider usage, not a metadata latency surrogate | aledane96, August 21, 2025, #8667, usage | |
ModuleNotFoundError | LangChain integration dependencies below the SDK requirement | Follow the compatible SDK/server/library matrix | upgrade guide |
The October 31, 2026 update by Marc Klingen announces the new SDK generation; the older contributor report does not establish a defect in it.
Missing
- The linked source does not confirm: a metadata latency number does not define span duration.
- The linked source does not confirm: use separate project credentials when access isolation is needed (environments).
- The linked source does not confirm: Flush can run masking synchronously and adds export wait time (batching).
- The linked source does not confirm: the batching example
flush_at=100,flush_interval=1in the linked batching FAQ. - No measured workload, event-volume budget or acceptable latency overhead is available, so no single sampling rate/flush interval can be selected as meeting that budget.
- Decorator capture controls do not suppress explicit input/output updates or every provider integration. Inspect exported synthetic spans after masking before admitting sensitive traffic.
Checked
2026-11-12; release, compatibility, SDK, environment, instrumentation, usage, sampling, batching and troubleshooting references, October update and contributor report read. No instrumentation or provider commands executed.
Started from a post by @Langfuse, packaged by the editor. Original post