refac: modernize type annotations (PEP 604 / PEP 585)
This commit is contained in:
@@ -3,11 +3,13 @@ import traceback
|
||||
from typing import Collection, Union
|
||||
|
||||
from aiohttp import (
|
||||
TraceRequestStartParams,
|
||||
TraceRequestEndParams,
|
||||
TraceRequestExceptionParams,
|
||||
TraceRequestStartParams,
|
||||
)
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, status
|
||||
from open_webui.utils.telemetry.constants import SPAN_REDIS_TYPE, SpanAttributes
|
||||
from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor
|
||||
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
||||
from opentelemetry.instrumentation.httpx import (
|
||||
HTTPXClientInstrumentor,
|
||||
@@ -19,16 +21,12 @@ from opentelemetry.instrumentation.logging import LoggingInstrumentor
|
||||
from opentelemetry.instrumentation.redis import RedisInstrumentor
|
||||
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
||||
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
|
||||
from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor
|
||||
from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor
|
||||
from opentelemetry.trace import Span, StatusCode
|
||||
from redis import Redis
|
||||
from redis.cluster import RedisCluster
|
||||
from requests import PreparedRequest, Response
|
||||
from sqlalchemy import Engine
|
||||
from fastapi import status
|
||||
|
||||
from open_webui.utils.telemetry.constants import SPAN_REDIS_TYPE, SpanAttributes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
import logging
|
||||
from base64 import b64encode
|
||||
from opentelemetry.sdk._logs import (
|
||||
LoggingHandler,
|
||||
LoggerProvider,
|
||||
|
||||
from open_webui.env import (
|
||||
OTEL_LOGS_BASIC_AUTH_PASSWORD,
|
||||
OTEL_LOGS_BASIC_AUTH_USERNAME,
|
||||
OTEL_LOGS_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_LOGS_EXPORTER_OTLP_INSECURE,
|
||||
OTEL_LOGS_OTLP_SPAN_EXPORTER,
|
||||
OTEL_SERVICE_NAME,
|
||||
)
|
||||
from opentelemetry._logs import set_logger_provider
|
||||
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
|
||||
from opentelemetry.exporter.otlp.proto.http._log_exporter import (
|
||||
OTLPLogExporter as HttpOTLPLogExporter,
|
||||
)
|
||||
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
|
||||
from opentelemetry._logs import set_logger_provider
|
||||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
||||
from open_webui.env import (
|
||||
OTEL_SERVICE_NAME,
|
||||
OTEL_LOGS_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_LOGS_EXPORTER_OTLP_INSECURE,
|
||||
OTEL_LOGS_BASIC_AUTH_USERNAME,
|
||||
OTEL_LOGS_BASIC_AUTH_PASSWORD,
|
||||
OTEL_LOGS_OTLP_SPAN_EXPORTER,
|
||||
from opentelemetry.sdk._logs import (
|
||||
LoggerProvider,
|
||||
LoggingHandler,
|
||||
)
|
||||
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
|
||||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
||||
|
||||
|
||||
def setup_logging():
|
||||
|
||||
@@ -20,38 +20,36 @@ from __future__ import annotations
|
||||
import datetime
|
||||
import logging
|
||||
import time
|
||||
from typing import Dict, Iterable, List, Optional
|
||||
from base64 import b64encode
|
||||
from typing import Dict, Iterable, List, Optional
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from open_webui.env import (
|
||||
OTEL_METRICS_BASIC_AUTH_PASSWORD,
|
||||
OTEL_METRICS_BASIC_AUTH_USERNAME,
|
||||
OTEL_METRICS_EXPORT_INTERVAL_MILLIS,
|
||||
OTEL_METRICS_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_METRICS_EXPORTER_OTLP_INSECURE,
|
||||
OTEL_METRICS_OTLP_SPAN_EXPORTER,
|
||||
OTEL_SERVICE_NAME,
|
||||
)
|
||||
from open_webui.models.users import User
|
||||
from opentelemetry import metrics
|
||||
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
|
||||
OTLPMetricExporter,
|
||||
)
|
||||
|
||||
from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
|
||||
OTLPMetricExporter as OTLPHttpMetricExporter,
|
||||
)
|
||||
from opentelemetry.sdk.metrics import MeterProvider
|
||||
from opentelemetry.sdk.metrics.view import View
|
||||
from opentelemetry.sdk.metrics.export import (
|
||||
PeriodicExportingMetricReader,
|
||||
)
|
||||
from opentelemetry.sdk.metrics.view import View
|
||||
from opentelemetry.sdk.resources import Resource
|
||||
from sqlalchemy import Engine, func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from open_webui.env import (
|
||||
OTEL_SERVICE_NAME,
|
||||
OTEL_METRICS_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_METRICS_BASIC_AUTH_USERNAME,
|
||||
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 User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
from fastapi import FastAPI
|
||||
from opentelemetry import trace
|
||||
from base64 import b64encode
|
||||
|
||||
from fastapi import FastAPI
|
||||
from open_webui.env import (
|
||||
ENABLE_OTEL_METRICS,
|
||||
ENABLE_OTEL_TRACES,
|
||||
OTEL_BASIC_AUTH_PASSWORD,
|
||||
OTEL_BASIC_AUTH_USERNAME,
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_EXPORTER_OTLP_INSECURE,
|
||||
OTEL_OTLP_SPAN_EXPORTER,
|
||||
OTEL_SERVICE_NAME,
|
||||
)
|
||||
from open_webui.utils.telemetry.instrumentors import Instrumentor
|
||||
from open_webui.utils.telemetry.metrics import setup_metrics
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||
OTLPSpanExporter as HttpOTLPSpanExporter,
|
||||
@@ -9,20 +22,6 @@ from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
||||
from opentelemetry.sdk.trace import TracerProvider
|
||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
||||
from sqlalchemy import Engine
|
||||
from base64 import b64encode
|
||||
|
||||
from open_webui.utils.telemetry.instrumentors import Instrumentor
|
||||
from open_webui.utils.telemetry.metrics import setup_metrics
|
||||
from open_webui.env import (
|
||||
OTEL_SERVICE_NAME,
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT,
|
||||
OTEL_EXPORTER_OTLP_INSECURE,
|
||||
ENABLE_OTEL_TRACES,
|
||||
ENABLE_OTEL_METRICS,
|
||||
OTEL_BASIC_AUTH_USERNAME,
|
||||
OTEL_BASIC_AUTH_PASSWORD,
|
||||
OTEL_OTLP_SPAN_EXPORTER,
|
||||
)
|
||||
|
||||
|
||||
def setup(app: FastAPI, db_engine: Engine):
|
||||
|
||||
Reference in New Issue
Block a user