[PR #20716] [CLOSED] fix(telemetry): respect OTel env headers and instrument LLM token usage #41375

Closed
opened 2026-04-25 13:37:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20716
Author: @execsumo
Created: 1/16/2026
Status: Closed

Base: mainHead: fix/otel-braintrust-config


📝 Commits (1)

  • 0dbaaa4 fix(otel): allow env vars to override empty headers and add token usage instrumentation

📊 Changes

3 files changed (+21 additions, -4 deletions)

View changed files

📝 backend/open_webui/utils/telemetry/instrumentors.py (+17 -0)
📝 backend/open_webui/utils/telemetry/metrics.py (+2 -2)
📝 backend/open_webui/utils/telemetry/setup.py (+2 -2)

📄 Description

Problem

  1. OTel Headers Ignored: In setup.py and metrics.py, the headers argument was explicitly initialized as [] (if no internal basic auth was set). This value is passed to the OTel exporter, causing it to ignore the standard OTEL_EXPORTER_OTLP_HEADERS environment variable. This broke integration with OTel providers that rely on header-based authentication (e.g., Braintrust, Honeycomb).
  2. Missing Token Usage: When using Open WebUI as a proxy, token usage data returned by upstream providers (like LiteLLM) in HTTP headers (e.g., x-openai-usage) was not being captured in the OTel traces.

Solution

  1. Allow Env Var Fallback: Changed the exporter initialization to pass headers=(headers or None). Passing None allows the OpenTelemetry SDK to correctly fall back to reading headers from the environment.
  2. Capture Usage Headers: Updated instrumentors.py to inspect response headers in aiohttp and httpx hooks. Start capturing headers matching "usage", "token", or "x-request-id" and add them as span attributes (prefixed with llm.header.).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20716 **Author:** [@execsumo](https://github.com/execsumo) **Created:** 1/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/otel-braintrust-config` --- ### 📝 Commits (1) - [`0dbaaa4`](https://github.com/open-webui/open-webui/commit/0dbaaa405c172e638c5256c0e12eb987a0e759af) fix(otel): allow env vars to override empty headers and add token usage instrumentation ### 📊 Changes **3 files changed** (+21 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/telemetry/instrumentors.py` (+17 -0) 📝 `backend/open_webui/utils/telemetry/metrics.py` (+2 -2) 📝 `backend/open_webui/utils/telemetry/setup.py` (+2 -2) </details> ### 📄 Description ## Problem 1. **OTel Headers Ignored**: In [setup.py](cci:7://file:///opt/stacks/openwebui/data/patches/setup.py:0:0-0:0) and [metrics.py](cci:7://file:///opt/stacks/openwebui/data/patches/metrics.py:0:0-0:0), the `headers` argument was explicitly initialized as `[]` (if no internal basic auth was set). This value is passed to the OTel exporter, causing it to ignore the standard `OTEL_EXPORTER_OTLP_HEADERS` environment variable. This broke integration with OTel providers that rely on header-based authentication (e.g., Braintrust, Honeycomb). 2. **Missing Token Usage**: When using Open WebUI as a proxy, token usage data returned by upstream providers (like LiteLLM) in HTTP headers (e.g., `x-openai-usage`) was not being captured in the OTel traces. ## Solution 1. **Allow Env Var Fallback**: Changed the exporter initialization to pass `headers=(headers or None)`. Passing `None` allows the OpenTelemetry SDK to correctly fall back to reading headers from the environment. 2. **Capture Usage Headers**: Updated [instrumentors.py](cci:7://file:///opt/stacks/openwebui/data/patches/instrumentors.py:0:0-0:0) to inspect response headers in `aiohttp` and `httpx` hooks. Start capturing headers matching "usage", "token", or "x-request-id" and add them as span attributes (prefixed with `llm.header.`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 13:37:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41375