From 035b981e11a549c6226ac0346f3747f454767ae2 Mon Sep 17 00:00:00 2001 From: Lorenzo Maffioli <63981558+lorenzophys@users.noreply.github.com> Date: Wed, 11 Mar 2026 21:27:06 +0100 Subject: [PATCH] feat(otel): introduce an environment variable to control the export interval of otel metrics (#22529) --- backend/open_webui/env.py | 3 +++ backend/open_webui/utils/telemetry/metrics.py | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 30334d9c0..7cd3898ea 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -1007,6 +1007,9 @@ OTEL_TRACES_SAMPLER = os.environ.get( ).lower() OTEL_BASIC_AUTH_USERNAME = os.environ.get("OTEL_BASIC_AUTH_USERNAME", "") OTEL_BASIC_AUTH_PASSWORD = os.environ.get("OTEL_BASIC_AUTH_PASSWORD", "") +OTEL_METRICS_EXPORT_INTERVAL_MILLIS = int( + os.environ.get("OTEL_METRICS_EXPORT_INTERVAL_MILLIS", "10000") +) OTEL_METRICS_BASIC_AUTH_USERNAME = os.environ.get( "OTEL_METRICS_BASIC_AUTH_USERNAME", OTEL_BASIC_AUTH_USERNAME diff --git a/backend/open_webui/utils/telemetry/metrics.py b/backend/open_webui/utils/telemetry/metrics.py index cafe779d8..5ff1129b0 100644 --- a/backend/open_webui/utils/telemetry/metrics.py +++ b/backend/open_webui/utils/telemetry/metrics.py @@ -44,11 +44,10 @@ from open_webui.env import ( OTEL_METRICS_BASIC_AUTH_PASSWORD, OTEL_METRICS_OTLP_SPAN_EXPORTER, OTEL_METRICS_EXPORTER_OTLP_INSECURE, + OTEL_METRICS_EXPORT_INTERVAL_MILLIS, ) from open_webui.models.users import Users -_EXPORT_INTERVAL_MILLIS = 10_000 # 10 seconds - def _build_meter_provider(resource: Resource) -> MeterProvider: """Return a configured MeterProvider.""" @@ -67,7 +66,7 @@ def _build_meter_provider(resource: Resource) -> MeterProvider: OTLPHttpMetricExporter( endpoint=OTEL_METRICS_EXPORTER_OTLP_ENDPOINT, headers=headers ), - export_interval_millis=_EXPORT_INTERVAL_MILLIS, + export_interval_millis=OTEL_METRICS_EXPORT_INTERVAL_MILLIS, ) ] else: @@ -78,7 +77,7 @@ def _build_meter_provider(resource: Resource) -> MeterProvider: insecure=OTEL_METRICS_EXPORTER_OTLP_INSECURE, headers=headers, ), - export_interval_millis=_EXPORT_INTERVAL_MILLIS, + export_interval_millis=OTEL_METRICS_EXPORT_INTERVAL_MILLIS, ) ]