mirror of
https://github.com/open-webui/open-webui
synced 2025-06-14 10:20:52 +00:00
Merge pull request #13972 from jarrod-lowe/otel-attrs
Some checks failed
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11.x) (push) Has been cancelled
Python CI / Format Backend (3.12.x) (push) Has been cancelled
Some checks failed
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11.x) (push) Has been cancelled
Python CI / Format Backend (3.12.x) (push) Has been cancelled
feat: Add user details to opentelemetry spans
This commit is contained in:
commit
fbcc80485b
@ -13,6 +13,8 @@ import pytz
|
|||||||
from pytz import UTC
|
from pytz import UTC
|
||||||
from typing import Optional, Union, List, Dict
|
from typing import Optional, Union, List, Dict
|
||||||
|
|
||||||
|
from opentelemetry import trace
|
||||||
|
|
||||||
from open_webui.models.users import Users
|
from open_webui.models.users import Users
|
||||||
|
|
||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
@ -194,7 +196,17 @@ def get_current_user(
|
|||||||
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
|
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
|
||||||
)
|
)
|
||||||
|
|
||||||
return get_current_user_by_api_key(token)
|
user = get_current_user_by_api_key(token)
|
||||||
|
|
||||||
|
# Add user info to current span
|
||||||
|
current_span = trace.get_current_span()
|
||||||
|
if current_span:
|
||||||
|
current_span.set_attribute("client.user.id", user.id)
|
||||||
|
current_span.set_attribute("client.user.email", user.email)
|
||||||
|
current_span.set_attribute("client.user.role", user.role)
|
||||||
|
current_span.set_attribute("client.auth.type", "api_key")
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
# auth by jwt token
|
# auth by jwt token
|
||||||
try:
|
try:
|
||||||
@ -213,6 +225,14 @@ def get_current_user(
|
|||||||
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Add user info to current span
|
||||||
|
current_span = trace.get_current_span()
|
||||||
|
if current_span:
|
||||||
|
current_span.set_attribute("client.user.id", user.id)
|
||||||
|
current_span.set_attribute("client.user.email", user.email)
|
||||||
|
current_span.set_attribute("client.user.role", user.role)
|
||||||
|
current_span.set_attribute("client.auth.type", "jwt")
|
||||||
|
|
||||||
# Refresh the user's last active timestamp asynchronously
|
# Refresh the user's last active timestamp asynchronously
|
||||||
# to prevent blocking the request
|
# to prevent blocking the request
|
||||||
if background_tasks:
|
if background_tasks:
|
||||||
@ -234,6 +254,14 @@ def get_current_user_by_api_key(api_key: str):
|
|||||||
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Add user info to current span
|
||||||
|
current_span = trace.get_current_span()
|
||||||
|
if current_span:
|
||||||
|
current_span.set_attribute("client.user.id", user.id)
|
||||||
|
current_span.set_attribute("client.user.email", user.email)
|
||||||
|
current_span.set_attribute("client.user.role", user.role)
|
||||||
|
current_span.set_attribute("client.auth.type", "api_key")
|
||||||
|
|
||||||
Users.update_user_last_active_by_id(user.id)
|
Users.update_user_last_active_by_id(user.id)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
Loading…
Reference in New Issue
Block a user