
    ug                        U d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  G d de      Z G d de      Zdae
ej>                     e d<    ed      a!ee d<   de
e"   de
e"   de
e	e"e"f      deddf
dZ# ede      Z$	 d de"dede
e	e"ee"e%e&e'ee"   ee%   ee&   ee'   f   f      dee$ge$f   fdZ(de	e"ee"e%e&e'ee"   ee%   ee&   ee'   df	   f   ddfdZ)y)!    N)wraps)Enum)AnyCallableDictOptionalSequenceUnionTypeVar)trace)SERVICE_NAMEResource)TracerProvider)BatchSpanProcessor)OTLPSpanExporter)	Component)Systemc                   8    e Zd ZdZdZ	 dZ	 dZ	 dZ	 dede	fdZ
y	)
OpenTelemetryGranularityz+The granularity of the OpenTelemetry spans.none	operationoperation_and_segmentallotherreturnc                     t         j                  t         j                  t         j                  t         j                  g}|j                  |       |j                  |      k  S )zCompare two granularities.)r   ALLOPERATION_AND_SEGMENT	OPERATIONNONEindex)selfr   orders      ^/var/www/openai/venv/lib/python3.12/site-packages/chromadb/telemetry/opentelemetry/__init__.py__lt__zOpenTelemetryGranularity.__lt__$   sN     %(($::$..$))	
 {{4 5;;u#555    N)__name__
__module____qualname____doc__r    r   r   r   r   boolr%    r&   r$   r   r      s9    5DI/3;
C96C 6D 6r&   r   c                   $     e Zd Zdef fdZ xZS )OpenTelemetryClientsystemc                 4   t         |   |       t        |j                  j                  |j                  j
                  |j                  j                  t        |j                  j                  r|j                  j                               y d             y )Nr   )	super__init__	otel_initsettingschroma_otel_service_namechroma_otel_collection_endpointchroma_otel_collection_headersr   chroma_otel_granularity)r"   r/   	__class__s     r$   r2   zOpenTelemetryClient.__init__0   sr     OO44OO;;OO::$??:: 77			
 			
r&   )r'   r(   r)   r   r2   __classcell__)r9   s   @r$   r.   r.   /   s    
v 
 
r&   r.   tracerr   granularityotel_service_nameotel_collection_endpointotel_collection_headersotel_granularityr   c           	      6   |t         j                  k(  ryt        t        t	        |       i      }t        |      }|j                  t        t        t	        |      |                   t        j                  |       t        j                  t              a|ay)a4  Initializes module-level state for OpenTelemetry.

    Parameters match the environment variables which configure OTel as documented
    at https://docs.trychroma.com/deployment/observability.
    - otel_service_name: The name of the service for OTel tagging and aggregation.
    - otel_collection_endpoint: The endpoint to which OTel spans are sent
        (e.g. api.honeycomb.com).
    - otel_collection_headers: The headers to send with OTel spans
        (e.g. {"x-honeycomb-team": "abc123"}).
    - otel_granularity: The granularity of the spans to emit.
    N
attributes)resource)endpointheaders)r   r    r   r   strr   add_span_processorr   r   r   set_tracer_provider
get_tracerr'   r;   r<   )r=   r>   r?   r@   rD   providers         r$   r3   r3   B   s    " 3888L#6G2H#IJHx0H56/	
 
h' h'F"Kr&   T)bound
trace_nametrace_granularityrC   c                 4     dt         dt         f fd}|S )z!A decorator that traces a method.fr   c                      t        j                         rt                fd       }|S t                fd       }|S )Nc                  D  K   t         k  r | i | d {   S t        s | i | d {   S t        j                        5  t        dt        j
                  j                  d      i        | i | d {   cd d d        S 7 u7 a7 # 1 sw Y   y xY wwNrB   pod_nameHOSTNAMEr<   r;   start_as_current_spanadd_attributes_to_current_spanosenvirongetargskwargsrC   rQ   rO   rN   s     r$   async_wrapperz6trace_method.<locals>.decorator.<locals>.async_wrapper   s      %{2!"D!3F!333!"D!3F!33311*1T2#RZZ^^J%?@ "#D!3F!33	 UT 43
 4	 UTsI   B BB BB 
6B BBB B BBB c                      t         k  r | i |S t        s | i |S t        j                        5  t        dt        j
                  j                  d      i        | i |cd d d        S # 1 sw Y   y xY wrT   rW   r]   s     r$   wrapperz0trace_method.<locals>.decorator.<locals>.wrapper   s|     %{2d-f--d-f--11*1T2#RZZ^^J%?@ d-f-	 UTTs   2A44A=)asyncioiscoroutinefunctionr   )rQ   r`   rb   rC   rO   rN   s   `  r$   	decoratorztrace_method.<locals>.decorator   sN    &&q)1X
4 
4 !  1X
. 
. Nr&   )rL   )rN   rO   rC   re   s   ``` r$   trace_methodrf   j   s    * Q  1  D r&   c                     t         t        j                  k(  ryt        syt	        j
                         }|j                  | j                         D ci c]  \  }}|	|| c}}       yc c}}w )z#Add attributes to the current span.N)r<   r   r    r;   r   get_current_spanset_attributesitems)rC   spankvs       r$   rY   rY      sa    $ .333!!#D**:*:*<N*<$!QA*<NONs   
A+
A+
)N)*rc   rZ   	functoolsr   enumr   typingr   r   r   r   r	   r
   r   opentelemetryr   opentelemetry.sdk.resourcesr   r   opentelemetry.sdk.tracer   opentelemetry.sdk.trace.exportr   5opentelemetry.exporter.otlp.proto.grpc.trace_exporterr   chromadb.configr   r   r   r.   r;   Tracer__annotations__r<   rG   r3   rL   r+   floatintrf   rY   r,   r&   r$   <module>r{      s    	   J J J  > 2 S % "6t 68
) 
 "& %(@(H% H"#}"#&sm"# &d38n5"# /	"#
 
"#J Cx ( 	#77/7 	
	
7$ qc1f%7tPSMTNUOSM
	
	P 
Pr&   