[PR #14197] [MERGED] feat: Add OpenTelemetry Metrics Support via OTLP Exporter #62265

Closed
opened 2026-05-06 06:17:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/14197
Author: @jk-f5
Created: 5/22/2025
Status: Merged
Merged: 6/16/2025
Merged by: @tjbck

Base: devHead: otel_metrics


📝 Commits (2)

  • 6325613 Merge pull request #14675 from open-webui/dev
  • 210dc74 feat: Add OpenTelemetry Metrics Support via OTLP Exporter

📊 Changes

3 files changed (+121 additions, -1 deletions)

View changed files

📝 backend/open_webui/env.py (+1 -0)
backend/open_webui/utils/telemetry/metrics.py (+110 -0)
📝 backend/open_webui/utils/telemetry/setup.py (+10 -1)

📄 Description

Description:
This merge request introduces support for collecting and exporting OpenTelemetry metrics from Open WebUI using the OTLP protocol. The new implementation includes an HTTP middleware that tracks request counts and durations, and exports to the same collector endpoint used for traces. Metric collection is feature-flagged via the ENABLE_OTEL_METRICS environment variable.


Summary of changes:

  • New Feature: OpenTelemetry Metrics
    • Added backend/open_webui/utils/telemetry/metrics.py:
      • Initializes an OTLP MetricExporter and MeterProvider.
      • Automatically captures http.server.requests (counter) and http.server.duration (histogram).
      • Injects FastAPI middleware to track HTTP methods, route templates, and status codes.
      • Uses low-cardinality label sets to avoid performance issues.
    • The WebUI itself does NOT expose a /metrics endpoint; use an OTLP-compatible collector (such as the OpenTelemetry Collector) to expose Prometheus or other endpoints.
  • Configuration:
    • New env var: ENABLE_OTEL_METRICS (default: False, opt-in).
      • Plumbed in backend/open_webui/env.py.
  • Setup:
    • Extended the telemetry setup sequence (backend/open_webui/utils/telemetry/setup.py) to conditionally initialize metric collection if ENABLE_OTEL_METRICS is set.
  • Documentation and Comments:
    • Docstrings and inline comments were added to clarify usage and cardinality risks.

Usage:

  1. Set ENABLE_OTEL_METRICS=true in your environment.
  2. Set OTEL_EXPORTER_OTLP_ENDPOINT to point at your OpenTelemetry collector's OTLP/gRPC metrics receiver.
  3. Metrics on HTTP request throughput and latencies will be exported periodically.
  4. Reminder: to expose a Prometheus /metrics endpoint, configure your collector accordingly.

Testing:

  • Metrics are only sent if the feature is enabled.
  • Verified that tags include only method, route, and status_code for cardinality safety.
  • No breaking changes to trace or existing telemetry collectors.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 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/14197 **Author:** [@jk-f5](https://github.com/jk-f5) **Created:** 5/22/2025 **Status:** ✅ Merged **Merged:** 6/16/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `otel_metrics` --- ### 📝 Commits (2) - [`6325613`](https://github.com/open-webui/open-webui/commit/63256136ef8322210c01c2bb322097d1ccfb8c6f) Merge pull request #14675 from open-webui/dev - [`210dc74`](https://github.com/open-webui/open-webui/commit/210dc746f04a908d2190b01eebb9ead86be41e44) feat: Add OpenTelemetry Metrics Support via OTLP Exporter ### 📊 Changes **3 files changed** (+121 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/env.py` (+1 -0) ➕ `backend/open_webui/utils/telemetry/metrics.py` (+110 -0) 📝 `backend/open_webui/utils/telemetry/setup.py` (+10 -1) </details> ### 📄 Description **Description:** This merge request introduces support for collecting and exporting OpenTelemetry metrics from Open WebUI using the OTLP protocol. The new implementation includes an HTTP middleware that tracks request counts and durations, and exports to the same collector endpoint used for traces. Metric collection is feature-flagged via the `ENABLE_OTEL_METRICS` environment variable. --- **Summary of changes:** - **New Feature: OpenTelemetry Metrics** - Added `backend/open_webui/utils/telemetry/metrics.py`: - Initializes an OTLP MetricExporter and MeterProvider. - Automatically captures `http.server.requests` (counter) and `http.server.duration` (histogram). - Injects FastAPI middleware to track HTTP methods, route templates, and status codes. - Uses low-cardinality label sets to avoid performance issues. - The WebUI itself does NOT expose a `/metrics` endpoint; use an OTLP-compatible collector (such as the OpenTelemetry Collector) to expose Prometheus or other endpoints. - **Configuration:** - New env var: `ENABLE_OTEL_METRICS` (default: False, opt-in). - Plumbed in `backend/open_webui/env.py`. - **Setup:** - Extended the telemetry setup sequence (`backend/open_webui/utils/telemetry/setup.py`) to conditionally initialize metric collection if `ENABLE_OTEL_METRICS` is set. - **Documentation and Comments:** - Docstrings and inline comments were added to clarify usage and cardinality risks. --- **Usage:** 1. Set `ENABLE_OTEL_METRICS=true` in your environment. 2. Set `OTEL_EXPORTER_OTLP_ENDPOINT` to point at your OpenTelemetry collector's OTLP/gRPC metrics receiver. 3. Metrics on HTTP request throughput and latencies will be exported periodically. 4. *Reminder: to expose a Prometheus `/metrics` endpoint, configure your collector accordingly.* --- **Testing:** - Metrics are only sent if the feature is enabled. - Verified that tags include only method, route, and status_code for cardinality safety. - No breaking changes to trace or existing telemetry collectors. ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <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-05-06 06:17:56 -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#62265