refac
This commit is contained in:
1 parent
1dcbfd47fb
commit
bd3a3635ee
3 files changed
+36
-23
No files matched your search
@@ -19,7 +19,6 @@ 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.utils.access_control import has_permission
|
from open_webui.utils.access_control import has_permission
|
||||||
@@ -30,6 +29,7 @@ from open_webui.models.auths import Auths
|
|||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
|
|
||||||
from open_webui.env import (
|
from open_webui.env import (
|
||||||
|
ENABLE_OTEL,
|
||||||
ENABLE_PASSWORD_VALIDATION,
|
ENABLE_PASSWORD_VALIDATION,
|
||||||
OFFLINE_MODE,
|
OFFLINE_MODE,
|
||||||
LICENSE_BLOB,
|
LICENSE_BLOB,
|
||||||
@@ -327,12 +327,15 @@ async def get_current_user(
|
|||||||
user = get_current_user_by_api_key(request, token)
|
user = get_current_user_by_api_key(request, token)
|
||||||
|
|
||||||
# Add user info to current span
|
# Add user info to current span
|
||||||
current_span = trace.get_current_span()
|
if ENABLE_OTEL:
|
||||||
if current_span:
|
from opentelemetry import trace
|
||||||
current_span.set_attribute('client.user.id', user.id)
|
|
||||||
current_span.set_attribute('client.user.email', user.email)
|
current_span = trace.get_current_span()
|
||||||
current_span.set_attribute('client.user.role', user.role)
|
if current_span:
|
||||||
current_span.set_attribute('client.auth.type', 'api_key')
|
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
|
return user
|
||||||
|
|
||||||
@@ -369,12 +372,15 @@ async def get_current_user(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Add user info to current span
|
# Add user info to current span
|
||||||
current_span = trace.get_current_span()
|
if ENABLE_OTEL:
|
||||||
if current_span:
|
from opentelemetry import trace
|
||||||
current_span.set_attribute('client.user.id', user.id)
|
|
||||||
current_span.set_attribute('client.user.email', user.email)
|
current_span = trace.get_current_span()
|
||||||
current_span.set_attribute('client.user.role', user.role)
|
if current_span:
|
||||||
current_span.set_attribute('client.auth.type', 'jwt')
|
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
|
||||||
@@ -422,12 +428,15 @@ def get_current_user_by_api_key(request, api_key: str):
|
|||||||
raise HTTPException(status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED)
|
raise HTTPException(status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED)
|
||||||
|
|
||||||
# Add user info to current span
|
# Add user info to current span
|
||||||
current_span = trace.get_current_span()
|
if ENABLE_OTEL:
|
||||||
if current_span:
|
from opentelemetry import trace
|
||||||
current_span.set_attribute('client.user.id', user.id)
|
|
||||||
current_span.set_attribute('client.user.email', user.email)
|
current_span = trace.get_current_span()
|
||||||
current_span.set_attribute('client.user.role', user.role)
|
if current_span:
|
||||||
current_span.set_attribute('client.auth.type', 'api_key')
|
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_last_active_by_id(user.id)
|
Users.update_last_active_by_id(user.id)
|
||||||
return user
|
return user
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import sys
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from opentelemetry import trace
|
|
||||||
from open_webui.env import (
|
from open_webui.env import (
|
||||||
ENABLE_AUDIT_STDOUT,
|
ENABLE_AUDIT_STDOUT,
|
||||||
ENABLE_AUDIT_LOGS_FILE,
|
ENABLE_AUDIT_LOGS_FILE,
|
||||||
@@ -100,6 +100,8 @@ class InterceptHandler(logging.Handler):
|
|||||||
if not ENABLE_OTEL:
|
if not ENABLE_OTEL:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
from opentelemetry import trace
|
||||||
|
|
||||||
extras = {}
|
extras = {}
|
||||||
context = trace.get_current_span().get_span_context()
|
context = trace.get_current_span().get_span_context()
|
||||||
if context.is_valid:
|
if context.is_valid:
|
||||||
|
|||||||
@@ -1245,10 +1245,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query) {
|
if (query || eventFiles?.length) {
|
||||||
messageInput?.setText(query);
|
if (query) {
|
||||||
|
messageInput?.setText(query);
|
||||||
|
}
|
||||||
await tick();
|
await tick();
|
||||||
submitHandler(query);
|
submitHandler(query || '');
|
||||||
}
|
}
|
||||||
} else if ($page.url.searchParams.get('q')) {
|
} else if ($page.url.searchParams.get('q')) {
|
||||||
const q = $page.url.searchParams.get('q') ?? '';
|
const q = $page.url.searchParams.get('q') ?? '';
|
||||||
|
|||||||
Reference in new issue
Block a user