o
    
۾i                     @   s  U d dl Z d dlmZ d dlmZmZ ddlmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZmZmZ g dZeg ef Zeed< ed	ef Zeed
< ed	ef Zeed< ed	ef Zeed< ed	ef Zeed< dee	e
eefiZeeeeeeeef f ed< 	d+dededeeef dB fddZ dededefddZ!	d+dddddedB dedeeef dB defd d!Z"				d,ded"e#d#e#dB deeef dB d$ed%efd&d'Z$d(efd)d*Z%dS )-    N)Callable)Any	TypeAlias   )SpanKindextract_trace_contextinit_otel_tracerinit_otel_worker_tracerinstrument_otelis_otel_availablemanual_instrument_otelotel_import_error_traceback)SpanAttributescontains_trace_headersextract_trace_headerslog_tracing_disabled_warning)
instrumentinstrument_manualinit_tracermaybe_init_worker_traceris_tracing_availabler   r   r   r   r   r   r   BackendAvailableFunc.InstrumentFuncInstrumentManualFuncInitTracerFuncInitWorkerTracerFuncotel_REGISTERED_TRACING_BACKENDSinstrumenting_module_nameotlp_traces_endpointextra_attributesc                 C   s(   t d \}}}}}| r|| ||S d S Nr   r   )r   r   r    is_availableinit_tracer_fn_ r&   I/home/ubuntu/.local/lib/python3.10/site-packages/vllm/tracing/__init__.pyr   B      r   process_kindprocess_namec                 C   s(   t d \}}}}}| r|| ||S d S r!   r"   )r   r)   r*   r#   r%   init_worker_tracer_fnr&   r&   r'   r   N   r(   r    T	span_name
attributesrecord_exceptionobjr.   r/   r0   c                C   sF   | du rt jt|||dS td \}}}}}| r!|| |||dS | S )z4
    Generic decorator to instrument functions.
    Nr-   r   )funcr.   r/   r0   )	functoolspartialr   r   )r1   r.   r/   r0   r#   r%   otel_instrumentr&   r&   r'   r   Z   s    
r   
start_timeend_timecontextkindc           	      C   s.   t d \}}}}}| r|| |||||S dS )a  Manually create a span with explicit timestamps.

    Args:
        span_name: Name of the span to create.
        start_time: Start time in nanoseconds since epoch.
        end_time: Optional end time in nanoseconds. If None, ends immediately.
        attributes: Optional dict of span attributes.
        context: Optional trace context (e.g., from extract_trace_context).
        kind: Optional SpanKind (e.g., SpanKind.SERVER).
    r   Nr"   )	r.   r6   r7   r/   r8   r9   r#   r%   manual_instrument_fnr&   r&   r'   r   y   s   r   returnc                  C   s   dd t  D } t| S )z
    Returns True if any tracing backend (OTel, Profiler, etc.) is available.
    Use this to guard expensive tracing logic in the main code.
    c                 S   s   g | ]	\}}}}}|qS r&   r&   ).0r#   r%   r&   r&   r'   
<listcomp>   s    z(is_tracing_available.<locals>.<listcomp>)r   valuesany)check_availabler&   r&   r'   r      s   r   )N)NNNN)&r3   collections.abcr   typingr   r   r   r   r   r   r	   r
   r   r   r   utilsr   r   r   r   __all__boolr   __annotations__r   r   r   r   r   dictstrtupler   r   r   intr   r   r&   r&   r&   r'   <module>   s   
(



"
