Skip to content

Commit 035b981

Browse files
authored
feat(otel): introduce an environment variable to control the export interval of otel metrics (open-webui#22529)
1 parent 8da2956 commit 035b981

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

backend/open_webui/env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,9 @@ def parse_section(section):
10071007
).lower()
10081008
OTEL_BASIC_AUTH_USERNAME = os.environ.get("OTEL_BASIC_AUTH_USERNAME", "")
10091009
OTEL_BASIC_AUTH_PASSWORD = os.environ.get("OTEL_BASIC_AUTH_PASSWORD", "")
1010+
OTEL_METRICS_EXPORT_INTERVAL_MILLIS = int(
1011+
os.environ.get("OTEL_METRICS_EXPORT_INTERVAL_MILLIS", "10000")
1012+
)
10101013

10111014
OTEL_METRICS_BASIC_AUTH_USERNAME = os.environ.get(
10121015
"OTEL_METRICS_BASIC_AUTH_USERNAME", OTEL_BASIC_AUTH_USERNAME

backend/open_webui/utils/telemetry/metrics.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
OTEL_METRICS_BASIC_AUTH_PASSWORD,
4545
OTEL_METRICS_OTLP_SPAN_EXPORTER,
4646
OTEL_METRICS_EXPORTER_OTLP_INSECURE,
47+
OTEL_METRICS_EXPORT_INTERVAL_MILLIS,
4748
)
4849
from open_webui.models.users import Users
4950

50-
_EXPORT_INTERVAL_MILLIS = 10_000 # 10 seconds
51-
5251

5352
def _build_meter_provider(resource: Resource) -> MeterProvider:
5453
"""Return a configured MeterProvider."""
@@ -67,7 +66,7 @@ def _build_meter_provider(resource: Resource) -> MeterProvider:
6766
OTLPHttpMetricExporter(
6867
endpoint=OTEL_METRICS_EXPORTER_OTLP_ENDPOINT, headers=headers
6968
),
70-
export_interval_millis=_EXPORT_INTERVAL_MILLIS,
69+
export_interval_millis=OTEL_METRICS_EXPORT_INTERVAL_MILLIS,
7170
)
7271
]
7372
else:
@@ -78,7 +77,7 @@ def _build_meter_provider(resource: Resource) -> MeterProvider:
7877
insecure=OTEL_METRICS_EXPORTER_OTLP_INSECURE,
7978
headers=headers,
8079
),
81-
export_interval_millis=_EXPORT_INTERVAL_MILLIS,
80+
export_interval_millis=OTEL_METRICS_EXPORT_INTERVAL_MILLIS,
8281
)
8382
]
8483

0 commit comments

Comments
 (0)