Skip to content

feat: add langfuse plugin for LLM observability#13095

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

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

Conversation

@sihyeonn
Copy link
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)

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
Add auth.source option to ai-proxy and ai-proxy-multi plugins:
- source: "config" (default) - use auth values from plugin config directly
- source: "consumer_label" - lookup auth values from consumer labels

This allows per-consumer API keys for AI providers like OpenAI, Gemini, etc.

Example usage:
- Consumer labels: {"openai_api_key": "Bearer sk-xxx"}
- Plugin config: {"auth": {"source": "consumer_label", "header": {"Authorization": "openai_api_key"}}}

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
Consumer labels ending with '_secret' suffix are now automatically
encrypted when stored in etcd and decrypted when loaded.

This enables secure storage of sensitive data like API keys in
consumer labels without external secret management infrastructure.

Example:
- Label "openai_api_key_secret" will be encrypted in etcd
- Decrypted automatically when consumer is loaded

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
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>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request plugin labels Mar 18, 2026
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>
@Baoyuantop
Copy link
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.

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