Skip to content

Agent and Model Monitoring with Langfuse

The optional application-wide integration covers common model requests, multi-step agents and tools. It uses the pinned Langfuse 4.17.0 SDK. Monitoring is disabled by default and does not require a Langfuse account for ordinary platform use.

Configure the integration

Install the optional observability extra or the pinned dependency in egs/requirements/observability.txt into the selected project environment. egs/requirements/observability.lock.txt provides the base runtime plus this SDK with hashes. Preserve the separate Qlib and image-worker environments.

Set the following values in local .env, or the process environment. Never put real credentials in YAML, committed files, browser settings or chat messages.

Variable Purpose
ALL_IN_ONE_LANGFUSE_ENABLED Explicit global enablement; default false
LANGFUSE_BASE_URL The selected cloud or self-hosted instance; required explicitly
LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY Project credentials for that instance
ALL_IN_ONE_LANGFUSE_CAPTURE_CONTENT Optional prompt/output capture; default false
ALL_IN_ONE_LANGFUSE_ENVIRONMENT Environment label; default local

Sampling, export timeout, batching, shutdown budget and payload limits are in egs/config/models/observability.yaml. Restart the application after changing endpoint, credentials or exporter options. The SDK shares resources by project key within a process; changing instance endpoints without restarting is not supported.

Inspect traces

GET /api/v1/system/observability returns safe configuration status. active means the SDK initialized; it does not authenticate the project or certify endpoint reachability. Reading this status does not initiate export or call the monitoring server. Missing SDK or configuration leaves generation available and reports the reason.

Enabled model responses include a trace identifier and observation identifier when available. Use them in the configured Langfuse instance. Model requests contain no SDK-specific tracing fields: tracing remains outside the ordinary OpenAI-compatible request, and JSON repair/textual ReAct continue to work unchanged.

Observation Actual coverage
Workflow/agent GenericAgent, research teams, decision teams, strategy-agent workflows/roles and knowledge answering/retrieval
Generation Common HTTP, OpenAI SDK and LiteLLM SDK calls; legacy SSE requests; native CLI invocation wrappers
Attempt Individual actual HTTP/SDK network attempts, including retries
Tool GenericAgent tools, validated research evidence reads and keyword retrieval
Correlation Agent/role/session identifiers where supplied, thread-pool context and isolated streaming contexts

A logical model generation is recorded once even when multiple shared adapters wrap the same request. Its child attempts retain retry behavior. Reported token usage, model, duration, request duration, RPM waiting and retry count are attached when actually available. No token usage or price is estimated for a CLI that does not report it. Cost calculation in Langfuse depends on its model pricing configuration; unknown cost is not represented as a verified zero.

Native CLI coverage describes the platform invocation and returned metadata. It does not inspect internal CLI tools, private reasoning or unreported upstream model traffic. SSE usage is recorded only when the provider supplies it.

Privacy and failure behavior

Default export contains metadata and identifiers, without prompts, answers, retrieved documents, tool content, attachments or absolute workspace paths. Metadata uses an allowlist. Explicit content capture remains bounded and masks configured credentials, credential fields, authorization-like values and local paths before SDK ingestion.

The integration does not enable global automatic HTTP, database or process instrumentation. Exporter errors, missing configuration, failed updates and shutdown problems do not replace a model response or the original business error. Export uses batching; ordinary generations do not force a blocking flush. Shutdown has an explicit wait budget.

The previous ALL_IN_ONE_GENERIC_AGENT_LANGFUSE_* configuration remains available for the legacy GenericAgent adapter. Global enablement takes precedence for that adapter and joins its observations into the shared context, preventing duplicate generations. Prefer the global settings for new deployments.

Acceptance scope

The integration is validated with the real SDK against a local OTLP receiver and an ordinary local model endpoint. Tests inspect exported parent/child relationships, retries, actual usage, concurrent streams, thread propagation and secret/path/content exclusion. This verifies application-to-SDK-to-export behavior. A live Langfuse deployment/dashboard check additionally requires the user's locally configured instance; local collector acceptance does not claim that deployment test.

See monitoring principles and Python compatibility for architecture and supported runtime evidence.