mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
enh: OTEL_OTLP_SPAN_EXPORTER
This commit is contained in:
parent
bab1453b4c
commit
8b35ea6eea
2 changed files with 22 additions and 5 deletions
|
|
@ -579,6 +579,12 @@ OTEL_TRACES_SAMPLER = os.environ.get(
|
||||||
OTEL_BASIC_AUTH_USERNAME = os.environ.get("OTEL_BASIC_AUTH_USERNAME", "")
|
OTEL_BASIC_AUTH_USERNAME = os.environ.get("OTEL_BASIC_AUTH_USERNAME", "")
|
||||||
OTEL_BASIC_AUTH_PASSWORD = os.environ.get("OTEL_BASIC_AUTH_PASSWORD", "")
|
OTEL_BASIC_AUTH_PASSWORD = os.environ.get("OTEL_BASIC_AUTH_PASSWORD", "")
|
||||||
|
|
||||||
|
|
||||||
|
OTEL_OTLP_SPAN_EXPORTER = os.environ.get(
|
||||||
|
"OTEL_OTLP_SPAN_EXPORTER", "grpc"
|
||||||
|
).lower() # grpc or http
|
||||||
|
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# TOOLS/FUNCTIONS PIP OPTIONS
|
# TOOLS/FUNCTIONS PIP OPTIONS
|
||||||
####################################
|
####################################
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from opentelemetry import trace
|
from opentelemetry import trace
|
||||||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
||||||
|
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||||
|
OTLPSpanExporter as HttpOTLPSpanExporter,
|
||||||
|
)
|
||||||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
||||||
from opentelemetry.sdk.trace import TracerProvider
|
from opentelemetry.sdk.trace import TracerProvider
|
||||||
from sqlalchemy import Engine
|
from sqlalchemy import Engine
|
||||||
|
|
@ -16,6 +19,7 @@ from open_webui.env import (
|
||||||
ENABLE_OTEL_METRICS,
|
ENABLE_OTEL_METRICS,
|
||||||
OTEL_BASIC_AUTH_USERNAME,
|
OTEL_BASIC_AUTH_USERNAME,
|
||||||
OTEL_BASIC_AUTH_PASSWORD,
|
OTEL_BASIC_AUTH_PASSWORD,
|
||||||
|
OTEL_OTLP_SPAN_EXPORTER,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -35,11 +39,18 @@ def setup(app: FastAPI, db_engine: Engine):
|
||||||
headers = [("authorization", f"Basic {auth_header}")]
|
headers = [("authorization", f"Basic {auth_header}")]
|
||||||
|
|
||||||
# otlp export
|
# otlp export
|
||||||
exporter = OTLPSpanExporter(
|
if OTEL_OTLP_SPAN_EXPORTER == "http":
|
||||||
endpoint=OTEL_EXPORTER_OTLP_ENDPOINT,
|
exporter = HttpOTLPSpanExporter(
|
||||||
insecure=OTEL_EXPORTER_OTLP_INSECURE,
|
endpoint=OTEL_EXPORTER_OTLP_ENDPOINT,
|
||||||
headers=headers,
|
insecure=OTEL_EXPORTER_OTLP_INSECURE,
|
||||||
)
|
headers=headers,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
exporter = OTLPSpanExporter(
|
||||||
|
endpoint=OTEL_EXPORTER_OTLP_ENDPOINT,
|
||||||
|
insecure=OTEL_EXPORTER_OTLP_INSECURE,
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
trace.get_tracer_provider().add_span_processor(LazyBatchSpanProcessor(exporter))
|
trace.get_tracer_provider().add_span_processor(LazyBatchSpanProcessor(exporter))
|
||||||
Instrumentor(app=app, db_engine=db_engine).instrument()
|
Instrumentor(app=app, db_engine=db_engine).instrument()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue