mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-12 23:02:35 +00:00
feat(otel): add W3C TraceContext propagator for distributed trace correlation
Set up CompositePropagator with TraceContextTextMapPropagator and W3CBaggagePropagator so that trace context (traceparent/tracestate headers) is propagated to downstream services via instrumented HTTP clients (requests, httpx, aiohttp). Without this, each service starts its own trace root and there is no way to correlate Open WebUI spans with backend LLM service spans (e.g. LiteLLM, vLLM) in a trace viewer. All required classes are already in opentelemetry-api — no new dependencies needed.
This commit is contained in:
parent
20544d412e
commit
60a85ee140
1 changed files with 9 additions and 0 deletions
|
|
@ -1,5 +1,9 @@
|
|||
from fastapi import FastAPI
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.propagate import set_global_textmap
|
||||
from opentelemetry.propagators.composite import CompositePropagator
|
||||
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
|
||||
from opentelemetry.baggage.propagation import W3CBaggagePropagator
|
||||
|
||||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||
|
|
@ -30,6 +34,11 @@ def setup(app: FastAPI, db_engine: Engine):
|
|||
resource = Resource.create(attributes={SERVICE_NAME: OTEL_SERVICE_NAME})
|
||||
if ENABLE_OTEL_TRACES:
|
||||
trace.set_tracer_provider(TracerProvider(resource=resource))
|
||||
set_global_textmap(
|
||||
CompositePropagator(
|
||||
[TraceContextTextMapPropagator(), W3CBaggagePropagator()]
|
||||
)
|
||||
)
|
||||
|
||||
# Add basic auth header only if both username and password are not empty
|
||||
headers = []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue