mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-22 09:31:58 -05:00
[PR #24046] [CLOSED] fix(telemetry): run OTEL metric callbacks synchronously #98529
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24046
Author: @franciseliang99-dot
Created: 4/23/2026
Status: ❌ Closed
Base:
dev← Head:fix/otel-metrics-sync-callbacks📝 Commits (1)
fe8fcf3fix(telemetry): run OTEL metric callbacks synchronously📊 Changes
2 files changed (+35 additions, -8 deletions)
View changed files
📝
backend/open_webui/models/users.py(+23 -1)📝
backend/open_webui/utils/telemetry/metrics.py(+12 -7)📄 Description
OTEL observable-gauge callbacks run on the
PeriodicExportingMetricReaderthread, which has no event loop. The three async callbacks inutils/telemetry/metrics.py(observe_active_users,observe_total_registered_users,observe_users_active_today) returned coroutines instead of iterables ofObservation, causingTypeError: 'coroutine' object is not iterableon every export cycle.This PR:
COUNT(*)variants onUsersTable(get_num_users_sync,get_active_user_count_sync,get_num_users_active_today_sync) using the existing syncSessionLocalfromopen_webui/internal/db.py.defand points them at the new sync methods.Sync
SessionLocalis documented indb.pyas "used ONLY for startup config loading"; OTEL metric callbacks are the one legitimate runtime exception because OTel'sPeriodicExportingMetricReaderruns them on a worker thread outside any event loop. Option 2 (asyncio.run_coroutine_threadsafeagainst the captured main loop) was considered but would require a lifespan hook plus cross-thread scheduling per export, with no runtime advantage for metrics polled every ~30s.Closes #23936
Closes #23938
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.