new-api icon indicating copy to clipboard operation
new-api copied to clipboard

[PR #7313] Optional Langfuse gateway observability

Open kic635 opened this issue 2 months ago • 1 comments

Read This First

This is a feature request for the self-hosted New API gateway. It is not a report about a third-party hosting service, a reverse-engineered channel, a Coding Plan service, a Codex reverse proxy, or pass-through behavior.

The feature is proposed in PR #7313. This issue documents the use case, scope, limitations, and review questions for that PR. It does not assume that the feature should be accepted or merged.

Version

  • Target repository base commit: bdef117505247769268b209665fb3ad7554c3da7
  • Proposed implementation commit: 2168b2a703b1d1adfd73f840c54be55890a2db5f from PR #7313
  • Deployment source: Repository source / self-built
  • Database: Not applicable to this feature proposal; no schema change is proposed

Submission Checks

  • [x] I reviewed the project README, documentation links, and existing Issue/PR guidance before submitting this request.
  • [x] I reviewed related existing discussions, including #560 and #824. This is a concrete, scope-limited follow-up for PR #7313, not a claim that the topic has never been discussed.
  • [x] I have kept the proposed behavior optional and disabled by default.
  • [x] I have described the actual implementation status and the tests that were and were not completed.
  • [x] I have not removed the requested issue sections.
  • [x] I understand that maintainers have limited time and may reject, narrow, or close this request.

Agent

  • Tool: Codex / GitHub CLI
  • Tool version: Not recorded
  • Model: Not recorded
  • Host: CLI
  • Date (UTC): 2026-09-14

User Request

I would like to discuss adding an optional Langfuse gateway observability integration to New API and to have the concrete proposal reviewed through PR #7313.

Out of Scope — Refuse

  • Matched: No.
  • This is not a request for a Coding Plan integration, reverse-engineered channel, third-party API wrapper, Codex-specific reverse-proxy compatibility, pass-through behavior, or support for a third-party hosted service.

Kind

  • [ ] Bug
  • [x] Feature
  • [ ] Investigation
  • [ ] Other

Usage / Configuration / Integration Check

  • This is a feature request, not a usage or configuration question.
  • The proposed integration is for the New API gateway process itself. It is different from configuring a client application to send its own Langfuse traces.
  • The current proposal does not require Langfuse to be enabled. With LANGFUSE_ENABLED=false, the reporter should not start its worker or send network requests.
  • The current target branch does not provide this gateway-side reporter behavior; PR #7313 proposes it.
  • Verdict: new feature / maintainer design review.

Background

New API acts as an AI API gateway. The gateway can observe request outcomes, upstream channel selection, retries, response status, and usage records. For a self-hosted deployment, integrating Langfuse only in the calling application generally observes the caller-side span. A gateway-side integration can optionally add gateway-level metadata such as model, channel, retry, duration, status, and usage information.

The purpose of this proposal is to make that telemetry available as an opt-in integration for users who operate their own New API instance. The proposal is not intended to claim that every request should be traced or that Langfuse should become a project dependency for all installations.

Feature Description

PR #7313 proposes an optional Langfuse reporter inside the gateway with the following scope:

  • Record successful and failed gateway request outcomes.
  • Record model, token usage, duration, HTTP status, streaming status, and channel metadata where those values are available in the existing request and consumption-log paths.
  • Record retry metadata and correlate events with request, trace, session, and project identifiers where those identifiers are available.
  • Use a bounded asynchronous queue and batched ingestion so the Langfuse network request is not part of the primary request path.
  • Keep the feature disabled by default.
  • Do not start the background worker or send telemetry when the feature is disabled, credentials are missing, or the sampling rate is zero.
  • Keep prompt and completion capture disabled by default.
  • Apply a configurable maximum byte limit if content capture is explicitly enabled.
  • Prevent Langfuse network failures, timeouts, HTTP errors, and queue overflow from changing the original gateway response.
  • Require HTTPS before sending credentials or telemetry to the configured Langfuse host.
  • Attempt a bounded flush of queued events during application shutdown.
  • Add configuration examples and unit tests for the reporter behavior.

Use Case

A user operates a self-hosted New API gateway and wants to understand how requests behave after entering the gateway, including request duration, model and channel metadata, retry information, response status, and usage-related fields. They may already use Langfuse or a similar observability platform for surrounding applications and want the gateway to produce compatible, optional telemetry.

The feature would be useful for debugging and operational analysis, but it should not make the gateway dependent on Langfuse availability and should not upload sensitive prompt or completion content by default.

Data and Privacy Boundaries

  • The integration is disabled by default.
  • Prompt and completion content are not exported unless the operator explicitly enables content capture.
  • Explicitly captured content is truncated to a configurable maximum size.
  • Credentials and telemetry are sent only to an HTTPS host.
  • Langfuse failures do not fail the original request.
  • Because the reporter is asynchronous, events may be lost during process termination, queue overflow, network failure, or other failures. The implementation does not claim lossless delivery.
  • This proposal does not define retention, access control, or privacy policies for the operator's Langfuse deployment; those remain deployment responsibilities and should be reviewed by maintainers for project requirements.

Research

Repository and Documentation

  • README: New API is a self-hosted AI API gateway and documents deployment, supported interfaces, and operational configuration.
  • PR template: New features should be associated with an Issue and should provide a focused description and verification evidence.
  • Current repository search: the proposed behavior is not described as an existing gateway-side Langfuse reporter in the target branch documentation.

Relevant PR Code Paths

The implementation in PR #7313 currently touches or adds the following areas:

  • pkg/langfuse/: reporter configuration, queueing, batching, ingestion, counters, shutdown, and tests.
  • controller/relay.go: publish gateway failure telemetry without changing the primary response.
  • model/log.go: map available consumption-log metadata into telemetry events.
  • main.go: initialize and close the optional reporter.
  • .env.example: document the opt-in configuration.
  • pkg/langfuse/langfuse_test.go: test configuration, sampling, queueing, ingestion, error handling, HTTPS, and shutdown behavior.

These paths describe the current PR proposal and are included for maintainer review; they are not presented as an approved architecture.

Verification

The current PR description records these completed checks:

  • go test ./pkg/langfuse ./model
  • go test ./controller -run ^
  • Unit tests for configuration, sampling, content truncation, queue behavior, HTTPS enforcement, HTTP ingestion, failures, and shutdown.

go test ./... was attempted, but the existing integration test suite exceeded the local execution window and was interrupted. Therefore, this issue does not claim that the full repository test suite has passed.

Experiments

Not applicable as a bug report. No upstream-versus-gateway comparison is required for this feature request. The proposed integration is intended to report metadata from the gateway's existing request and consumption-log paths rather than change upstream request behavior.

Working Theory

  • What is missing: an optional, gateway-side observability exporter for operators who want New API request and usage metadata in Langfuse.
  • Why it may be useful: the gateway sees request and retry information that may not be available to the calling application.
  • What would falsify the need: if maintainers determine that gateway-side telemetry is intentionally out of scope, or that the existing client-side integration is sufficient for the project's supported use cases.

Scope

In Scope

  • Optional Langfuse event reporting from the gateway.
  • Request outcome, timing, model, channel, retry, streaming, and usage metadata that already exists in the gateway path.
  • Safe defaults, bounded asynchronous delivery, HTTPS enforcement, and tests.

Out of Scope

  • Making Langfuse a required dependency.
  • Implementing or hosting the Langfuse platform.
  • Prompt management, evaluation datasets, user feedback, or other Langfuse platform features.
  • Changing model routing, billing calculations, upstream request formats, or response formats.
  • Guaranteeing lossless telemetry delivery.

This is a directional feature request and should be treated as maintainer alignment for PR #7313. The requested behavior can be narrowed or redesigned if the maintainers prefer a different integration boundary.

Proposed Direction

Please review whether the following acceptance criteria are appropriate:

  1. The feature is disabled by default and has no network side effect when disabled.
  2. Enabling it does not change the original request or response path when Langfuse is unavailable.
  3. Sensitive content is not captured by default.
  4. Credentials are not sent to non-HTTPS hosts.
  5. Queueing and batching are bounded and do not block normal requests indefinitely.
  6. The configuration and event fields are documented.
  7. The reporter behavior has focused automated tests.
  8. The project accepts the possible loss of asynchronous events during failures, or defines a different durability requirement.

Not Verified

  • Full go test ./... completion.
  • Production behavior with a real Langfuse deployment.
  • All supported database engines, because no schema change is proposed.
  • All upstream providers and channel-specific metadata availability.
  • Long-running load, queue saturation, and shutdown behavior under production traffic.
  • Final project policy for third-party observability destinations and telemetry retention.

Related

  • PR #7313: https://github.com/QuantumNous/new-api/pull/7313
  • Langfuse: https://github.com/langfuse/langfuse

kic635 avatar Sep 14 '26 02:09 kic635

[Bot Review]

感谢提交。当前 Issue 未使用项目规定的 Bug Report 或 Feature Request 模板,缺少“版本/version”和“提交确认/Submission Checks”等必需章节,因此无法按规范受理。请使用对应模板重新提交,欢迎补充后再次发起。