|
@@ -4,6 +4,7 @@ from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExport
|
|
|
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
|
|
from opentelemetry.sdk.trace import TracerProvider
|
|
|
from sqlalchemy import Engine
|
|
|
+from base64 import b64encode
|
|
|
|
|
|
from open_webui.utils.telemetry.exporters import LazyBatchSpanProcessor
|
|
|
from open_webui.utils.telemetry.instrumentors import Instrumentor
|
|
@@ -11,7 +12,10 @@ 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_METRICS,
|
|
|
+ OTEL_BASIC_AUTH_USERNAME,
|
|
|
+ OTEL_BASIC_AUTH_PASSWORD,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -22,8 +26,20 @@ def setup(app: FastAPI, db_engine: Engine):
|
|
|
resource=Resource.create(attributes={SERVICE_NAME: OTEL_SERVICE_NAME})
|
|
|
)
|
|
|
)
|
|
|
+
|
|
|
+ # Add basic auth header only if both username and password are not empty
|
|
|
+ headers = []
|
|
|
+ if OTEL_BASIC_AUTH_USERNAME and OTEL_BASIC_AUTH_PASSWORD:
|
|
|
+ auth_string = f"{OTEL_BASIC_AUTH_USERNAME}:{OTEL_BASIC_AUTH_PASSWORD}"
|
|
|
+ auth_header = b64encode(auth_string.encode()).decode()
|
|
|
+ headers = [("authorization", f"Basic {auth_header}")]
|
|
|
+
|
|
|
# otlp export
|
|
|
- exporter = OTLPSpanExporter(endpoint=OTEL_EXPORTER_OTLP_ENDPOINT)
|
|
|
+ exporter = OTLPSpanExporter(
|
|
|
+ endpoint=OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
|
+ insecure=OTEL_EXPORTER_OTLP_INSECURE,
|
|
|
+ headers=headers,
|
|
|
+ )
|
|
|
trace.get_tracer_provider().add_span_processor(LazyBatchSpanProcessor(exporter))
|
|
|
Instrumentor(app=app, db_engine=db_engine).instrument()
|
|
|
|