Langfuse integration
Langfuse is an LLM observability platform for traces, generations, scores and prompts. With this integration every request through the gateway becomes a Langfuse generation with its input, output, usage, cost, latency, model and metadata, so you can debug conversations and track quality per key, team or feature in Langfuse's own interface.
A real-world scenario
A product team wants to review a sample of real conversations every week to spot bad answers. They add the Langfuse callback from the Admin UI, and their application puts the conversation id in each request's metadata.trace_id. In Langfuse the team opens a trace and sees every turn of that conversation as a generation with the prompt, the answer, the tokens and the cost, scores the bad ones, and never touches the application or the gateway config.
Turn it on from the Admin UI
- Sign in as a proxy admin and open Settings, then Logging & Alerts. Click Add Callback.
- Pick Langfuse in the Callback dropdown and fill in Public Key, Secret Key, Host URL (leave it empty for Langfuse Cloud) and, if you want, Tracing Environment.
- Click Add Callback. The table shows a
langfuserow with the badge Success. - Open the row's actions menu and click Test, then look for the test generation in the Langfuse project.
Turn it on in the config file
spanway_settings:
success_callback: ["langfuse"]
failure_callback: ["langfuse"]
| Variable | Purpose |
|---|---|
LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY | Project credentials. |
LANGFUSE_HOST | Langfuse URL. Defaults to Langfuse Cloud. |
LANGFUSE_TRACING_ENVIRONMENT | Environment label on traces, such as production. |
LANGFUSE_FLUSH_INTERVAL | Seconds between batch flushes. |
LANGFUSE_DEBUG | Verbose integration logging. |
LANGFUSE_SAMPLE_RATE | Share of traces sent, from 0.0 to 1.0. Default 1.0, every trace. Lower it to cut Langfuse cost on high traffic, at the price of missing some requests. |
LANGFUSE_TIMEOUT | Seconds each export and API call may take. Default 20. |
LANGFUSE_MAX_RETRIES | How many times a failed export is sent again. Default 3. |
LANGFUSE_FLUSH_AT | How many events are sent in one batch. Default 512. |
LANGFUSE_RELEASE | Release label on traces. Default is the commit id your CI or deploy platform sets, when it sets one. |
LANGFUSE_BASE_URL | Used for the Langfuse URL when LANGFUSE_HOST is unset. |
LANGFUSE_OTEL_HOST | Host for the langfuse_otel callback, when it differs from LANGFUSE_HOST. |
LANGFUSE_PROMPT_CACHE_DEFAULT_TTL_SECONDS | Seconds a managed prompt fetched from Langfuse is cached. Default 60. |
Use langfuse_otel instead of langfuse to send traces over OpenTelemetry to Langfuse's OTLP endpoint. Check the connection with GET /health/services?service=langfuse, which sends a mock request and answers Mock LLM request made - check langfuse..
Trace fields from request metadata
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [{"role": "user", "content": "Summarize this ticket"}],
"metadata": {
"generation_name": "ticket-summary",
"trace_id": "ticket-4411",
"session_id": "agent-session-9",
"tags": ["support", "summaries"],
"version": "2026-10-14"
}
}'
Expected result: within the flush interval, Langfuse shows a trace ticket-4411 in session agent-session-9 with a generation named ticket-summary, tagged support and summaries, carrying the model, tokens, cost, and the gateway's key alias, team and user in its metadata.
generation_name names the generation, trace_id groups generations into one trace, session_id groups traces into a session, tags and version are stored on the trace, and the request's user field becomes the Langfuse user. The calling key alias, team and user from the gateway are added as metadata automatically.
Per-team projects
Attach Langfuse credentials to a team with a team callback, and its keys log to that project. See team logging. A client can also pass langfuse_public_key, langfuse_secret_key and langfuse_host in metadata for one request.
Prompts from Langfuse
With prompt_integration: langfuse in a prompt definition, the gateway fetches prompt templates from Langfuse prompt management and renders them for requests that send a prompt_id. See prompt management.
Redacting content
Set spanway_settings.turn_off_message_logging: true to send usage and cost without inputs and outputs. The Langfuse SDK itself can be routed through the gateway with the Langfuse pass-through.
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
| Nothing appears in Langfuse | Langfuse project | The keys belong to another project, or the host is wrong, or the batch has not flushed yet. | Check LANGFUSE_HOST, wait for LANGFUSE_FLUSH_INTERVAL, and look for Langfuse Layer Error in the gateway log. |
| 400 naming Host URL and Secret Key | Saving the callback in the Admin UI | The host changed while the stored secret was kept. | Retype the secret key with the new host. |
403 naming scoped_integrations | Team callback | Per team Langfuse projects need the license feature. | Use the gateway wide callback, or add the feature. |
| Generations show no input or output | Langfuse | turn_off_message_logging is on, or the request was under zero data retention. | That is by design. See what Spanway stores. |
Logs
| Level | Line | Meaning |
|---|---|---|
| ERROR | Langfuse Layer Error - <traceback> | Langfuse rejected a generation. The traceback holds Langfuse's answer, usually an authentication failure. |
| WARNING | Overwriting Langfuse <field> from request header | A request header set a trace field that the metadata also set. The header won. Normal. |
| ERROR | [Non-blocking] Langfuse Logger: Invalid prompt format. No prompt logged to Langfuse | The prompt could not be rendered for Langfuse. The generation was still sent without it. |
Related
- Logging for every destination and the fields each log entry carries.
- Team logging for per team projects.
- Prompt management for prompts fetched from Langfuse.
- Error reference and log reference.