Ë
    tPêjÆ  ã                   ó¶   — U d Z ddlZddlmZmZ ddlmZ ddlmZ dZ	ee
d<   dj                  e	«      Zee
d	<    eh d
£«      Zee
d<   dededdfd„Zdeddfd„Zy)u‡  FastAPI server-span instrumentation â€” the proxy mounts this at app creation.

``opentelemetry-instrumentation-fastapi`` creates the SERVER span for each HTTP
route and extracts inbound ``traceparent`` headers. This module owns the one call
site that attaches it to the proxy app, plus the passthrough span-naming hook, so
``proxy_server`` stays free of OTel details.

The ``FastAPIInstrumentor`` import is kept lazy (inside :func:`instrument_fastapi_app`,
after the gate check) so importing this module never requires the optional
``opentelemetry-instrumentation-fastapi`` package and pulls in nothing OTel-related
when the feature gate is off.
é    N)ÚAnyÚFinal)Úverbose_logger)Úis_otel_v2_enabled)z/healthz/metricsz/litellm-asset-prefixz/_nextz/uiz/swaggerz/docsz/redocz/openapi.jsonÚfaviconz/.well-knownÚ_DEFAULT_EXCLUDED_ROUTESú,Ú_DEFAULT_EXCLUDED_URLS>   ú	vertex-aiúeu.assemblyaiÚvllmÚazureÚcohereÚcursorÚgeminiÚmilvusÚopenaiÚbedrockÚmistralÚazure_aiÚ	anthropicÚ	vertex_aiÚ
assemblyaiÚopenai_passthroughÚPASSTHROUGH_PREFIXESÚspanÚscopeÚreturnc                 ód  — 	 | �| j                  «       sy|j                  d«      xs d}|j                  d«      xs d}|j                  d«      j                  dd«      d   }|t        v r7| j                  |› d|› �j                  «       «       | j                  d	|«       yy# t        $ r Y yw xY w)
u4  FastAPI ``server_request_hook``: give passthrough server spans a useful name.

    The instrumentation matches the route at span creation, so both the span name
    and ``http.route`` are set to the catch-all template (``/openai/{endpoint:path}``)
    before this hook runs. Rewrite both to the real request path so each upstream
    endpoint is distinguishable. (The ASGI ``http receive``/``http send`` sub-spans
    can't be renamed from here â€” their name is captured at creation â€” so they are
    dropped via ``exclude_spans`` at instrumentation time.)
    NÚpathÚ Úmethodú/é   r   ú z
http.route)	Úis_recordingÚgetÚlstripÚsplitr   Úupdate_nameÚstripÚset_attributeÚ	Exception)r   r   r    r"   Úfirst_segments        úd/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/integrations/otel/mount.pyÚ_passthrough_span_name_hookr0   D   s´   € ð
Øˆ<˜t×0Ñ0Ô2ØØ—i‘i Ó'Ò-¨2ˆØŸ	™	 (Ó+Ò1¨rˆØ#Ÿ{™{¨3Ó/×5Ñ5°c¸1Ó=¸aÑ@ˆØÔ0Ñ0Ø×Ñ ˜x q¨¨Ð/×5Ñ5Ó7Ô8Ø×Ñ˜|¨TÕ2ð 1øô ò Ùðús   ‚B# •BB# Â#	B/Â.B/Úappc                 ó$  — 	 t        «       syddlm} dt        j                  v rt        j                  j                  d«      nt        }|j                  | |t        ddg¬«       y# t        $ r }t        j                  d|«       Y d}~yd}~ww xY w)	uÀ  Attach OTel server-span instrumentation to the proxy FastAPI app.

    Safe no-op when the V2 gate is off or ``opentelemetry-instrumentation-fastapi``
    is unavailable. This MUST be called at app-creation time â€” once the lifespan
    runs, the middleware stack is frozen and ``instrument_app`` raises "Cannot add
    middleware after an application has started".

    No ``TracerProvider`` is passed, so the instrumentation binds to the OTel global
    ``ProxyTracerProvider``; the proxy publishes the real provider as the global
    after config load (see ``proxy_startup_event``), and the proxy delegates to it.
    That way server spans and gen-ai spans share one provider and the same trace.
    Nr   )ÚFastAPIInstrumentorÚ!OTEL_PYTHON_FASTAPI_EXCLUDED_URLSÚreceiveÚsend)Úexcluded_urlsÚserver_request_hookÚexclude_spansz,Skipping OTel V2 FastAPI instrumentation: %s)r   Ú%opentelemetry.instrumentation.fastapir3   ÚosÚenvironr'   r
   Úinstrument_appr0   r-   r   Údebug)r1   r3   r7   Úes       r/   Úinstrument_fastapi_appr@   [   s�   € ðPÜ!Ô#Øõ 	Nð 3´b·j±jÑ@ô �J‰J�N‰NÐ>Ô?ä'ð 	ð
 	×*Ñ*ØØ'Ü ;ð % fÐ-ð 	+õ 	
øô ò PÜ×ÑÐKÈQ×OÑOûðPús   ‚
A& �AA& Á&	BÁ/B
Â
B)Ú__doc__r;   Útypingr   r   Úlitellm._loggingr   Ú&litellm.integrations.otel.model.configr   r   Ú__annotations__Újoinr
   Ú	frozensetr   Údictr0   r@   © ó    r/   ú<module>rK      s‡   ðòó 
ß å +Ý Eð#Ð ˜%ó ð !$§¡Ð)AÓ BÐ ˜Ó Bñ (òóÐ �eó ð, cð °$ð ¸4ó ð.'P ð 'P¨ô 'PrJ   