Skip to content

feat: add langfuse plugin for LLM observability#13095

Open
sihyeonn wants to merge 3 commits intoapache:masterfrom
sihyeonn:feat/langfuse-plugin
Open

feat: add langfuse plugin for LLM observability#13095
sihyeonn wants to merge 3 commits intoapache:masterfrom
sihyeonn:feat/langfuse-plugin

Conversation

@sihyeonn
Copy link
Copy Markdown
Contributor

@sihyeonn sihyeonn commented Mar 18, 2026

Description

Add a new langfuse plugin that sends LLM request traces to Langfuse for AI observability. The plugin uses the batch-processor-manager pattern (same as http-logger) to send trace data via Langfuse's ingestion API.

Key features:

  • Auto-detect AI endpoints via configurable URI suffix patterns
  • Generate trace-create and generation-create batch items per request
  • W3C traceparent header parsing and propagation for distributed tracing
  • Token usage extraction with priority: ctx.ai_token_usage (ai-proxy) > nginx vars > response body parsing
  • Support X-Langfuse-Tags and X-Langfuse-Metadata custom headers
  • encrypt_fields for secret key protection in etcd
  • Connection keepalive for Langfuse API calls

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request plugin labels Mar 18, 2026
@Baoyuantop
Copy link
Copy Markdown
Contributor

This PR contains three fundamentally different features:

  1. Add a Langfuse logging plugin (apisix/plugins/langfuse.lua, line 687)

  2. Consumer label encryption/decryption (apisix/admin/consumers.lua + apisix/consumer.lua)

  3. ai-proxy consumer_label authentication source (apisix/plugins/ai-proxy/base.lua + schema.lua)

Apache APISIX community practice requires each PR to focus on a single feature. These three features have different review dimensions, testing requirements, and regression risks; please separate them into independent PRs.

@Baoyuantop
Copy link
Copy Markdown
Contributor

Hi @sihyeonn, following up on the previous review comments. Please let us know if you have any updates. Thank you.

@sihyeonn sihyeonn force-pushed the feat/langfuse-plugin branch from 187a719 to d3003c0 Compare April 2, 2026 23:48
@Baoyuantop
Copy link
Copy Markdown
Contributor

Hi @sihyeonn, my suggestion is to only keep the feature-related code in the current PR, and submit other changes in separate PRs.

Add a new langfuse plugin that sends AI request traces to Langfuse
via its ingestion API using batch-processor-manager pattern.

Features:
- Auto-detect AI endpoints (configurable patterns)
- Generate trace-create and generation-create batch items per request
- W3C traceparent header parsing and propagation
- Token usage extraction (ai-proxy ctx > nginx vars > response body)
- Support for X-Langfuse-Tags and X-Langfuse-Metadata headers
- Basic auth with encrypt_fields for secret key protection
- Connection keepalive for Langfuse API calls

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
Move langfuse_host, langfuse_public_key, langfuse_secret_key, ssl_verify,
timeout, detect_ai_requests, and ai_endpoints from per-route schema to
metadata_schema (plugin_attr), following the opentelemetry plugin pattern.

Per-route schema now only contains include_metadata.
Remove encrypt_fields (custom feature, not in OSS).

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
Remove /v1-prefixed entries since has_suffix matching already covers
them via shorter suffixes (e.g. /chat/completions matches both
/chat/completions and /v1/chat/completions).

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
@sihyeonn sihyeonn force-pushed the feat/langfuse-plugin branch from d3003c0 to 9c4b25a Compare April 9, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants