
    !<i                    \   d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	m
Z
 d dl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mZ d d
lmZ d dlmZ d dlmZ  e            ZdZ	 d1d2dZ 	 	 d3d4dZ!d5d#Z"	 d1d$Z#d6d&Z$d7d(Z%d) Z&d8d*Z'd8d+Z(ed9d.            Z)ed:d/            Z*ed:d0            Z+dS );    )annotationsN)contextmanager)import_module)escapesub)AnyDict	GeneratorSequence)ObjectProxy)contexttrace)"_SUPPRESS_HTTP_INSTRUMENTATION_KEY_SUPPRESS_INSTRUMENTATION_KEY)extract)
StatusCode)TraceContextTextMapPropagatorsuppress_instrumentationobjr   
attributesSequence[str]existingDict[str, str] | NonereturnDict[str, str]c                    i }|r|                     |           |D ]'}t          | |d           }|t          |          ||<   (|S N)updategetattrstr)r   r   r   	extractedattrvalues         /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/utils.pyextract_attributes_from_objectr%   0   sa     !#I #""" ) )T4((!%jjIdO    TFstatusintallow_redirectboolserver_spanr   c                    t          | t                    st          j        S | dk     rt          j        S | dk    rt          j        S | dk    r|rt          j        S | dk    r|rt          j        S t          j        S )z}Converts an HTTP status code to an OpenTelemetry canonical status code

    Args:
        status (int): HTTP status code
    d   i+  i  i  )
isinstancer(   r   UNSETERROR)r'   r)   r+   s      r$   http_status_to_status_coder1   =   sx     fc""  ||}}}}}}}}r&   objectr"   r    c                   t          | t                    r	 |                     dd          \  }}n&# t          $ r}t	          d|  d          |d}~ww xY wt          |          }	 t          ||          } n)# t          $ r}t	          d| d| d          |d}~ww xY wt          | |d          }|r=t          |t                    r*t          |d	          rt          | ||j                   dS dS dS dS )
aM  Given a function that was wrapped by wrapt.wrap_function_wrapper, unwrap it

    The object containing the function to unwrap may be passed as dotted module path string.

    Args:
        obj: Object that holds a reference to the wrapped function or dotted import path as string
        attr (str): Name of the wrapped function
    .   zCannot parse 'z' as dotted import pathNzCannot import 'z' from ''__wrapped__)r.   r    rsplit
ValueErrorImportErrorr   r   AttributeErrorr   hasattrsetattrr7   )r   r"   module_path
class_nameexcmodulefuncs          r$   unwraprC   V   s\    #s 	&)jja&8&8#K 	 	 	==== 	 {++	&*--CC 	 	 	?*??f??? 	
 3d##D -
4-- -'$2N2N -T4+,,,,,- - - - - -s,   1 
AAA'A8 8
BBBc                >   dx}x}}t          j                    t           j        u r7t          ||          }t	          j        |          }t           j        j        }n$t	          j                    }t           j        j	        }| 
                    |||||          }	|	|fS )a  Returns internal or server span along with the token which can be used by caller to reset context


    Args:
        tracer : tracer in use by given instrumentation library
        span_name (string): name of the span
        start_time : start time of the span
        context_carrier : object which contains values that are
            used to construct a Context. This object
            must be paired with an appropriate getter
            which understands how to extract a value from it.
        context_getter : an object which contains a get function that can retrieve zero
            or more values from the carrier and a keys function that can get all the keys
            from carrier.
    N)getter)namer   kind
start_timer   )r   get_current_spanINVALID_SPANr   r   attachSpanKindSERVERget_currentINTERNAL
start_span)
tracer	span_namerH   context_carriercontext_getterr   tokenctx	span_kindspans
             r$   _start_internal_or_server_spanrY   s   s    0 #"E"C)5#555on===s##N)		!##N+	   D ;r&   sc                    t          | t          t          f          s| S t          j                            |           }|                    dd          S )N%z%%)r.   r    bytesurllibparsequotereplace)rZ   quoteds     r$   
_url_quoterc      sH    a#u&& \""F
 >>#t$$$r&   dict[str, Any]c                 >    i } t                               |            | S )zs
    Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
    OpenTelemetry execution context.
    )
propagatorinject)_headerss    r$   _get_opentelemetry_valuesri      s"      "HhOr&   c                H    t          t          |           | dd|           S )Nz(?!$) )r   r   )python_path	directorypath_separators      r$   _python_path_without_directoryro      s3    94~444
  r&   c                 h    t          j        t                    pt          j        t                     S r   )r   	get_valuer   #_SUPPRESS_INSTRUMENTATION_KEY_PLAIN r&   r$   is_instrumentation_enabledrt      s0    788 	B@AA r&   c                 R    t                      ot          j        t                     S r   )rt   r   rq   r   rs   r&   r$   is_http_instrumentation_enabledrv      s,    %'' 0A*1 1 - r&   keysGenerator[None]c               '     K   t          j                    }| D ]}t          j        |d|          }t          j        |          }	 dV  |rt          j        |           dS dS # |rt          j        |           w w xY w),Suppress instrumentation within the context.TN)r   rN   	set_valuerK   detach)rw   rV   keyrU   s       r$   _suppress_instrumentationr~      s       


C 0 0T3//N3E" 	"N5!!!!!	" 	"5 	"N5!!!!	"s   A$ $A=c               #  x   K   t          t          t                    5  dV  ddd           dS # 1 swxY w Y   dS rz   N)r~   r   rr   rs   r&   r$   r   r      s       
#%'J
 
   	                 s   /33c               #  l   K   t          t                    5  dV  ddd           dS # 1 swxY w Y   dS r   )r~   r   rs   r&   r$   suppress_http_instrumentationr      s       
##E	F	F                   s   )--r   )r   r   r   r   r   r   r   r   )TF)r'   r(   r)   r*   r+   r*   r   r   )r   r2   r"   r    )rZ   r   r   r    )r   rd   )r   r*   )rw   r    r   rx   )r   rx   ),
__future__r   urllib.parser^   
contextlibr   	importlibr   rer   r   typingr   r	   r
   r   wraptr   opentelemetryr   r   opentelemetry.contextr   r   opentelemetry.propagater   opentelemetry.tracer   ,opentelemetry.trace.propagation.tracecontextr   rf   rr   r%   r1   rC   rY   rc   ri   ro   rt   rv   r~   r   r   rs   r&   r$   <module>r      sn   # " " " " "     % % % % % % # # # # # #         1 1 1 1 1 1 1 1 1 1 1 1       ( ( ( ( ( ( ( (        , + + + + + * * * * * *      +*,,
  $ LP
 
 
 
 
      2- - - -F ' ' ' 'T% % % %            
" 
" 
" 
"          r&   