
    Vi                    x   S SK Jr  S SKrS SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJrJrJr  S SKJr  S SKJrJr  S S	KJrJr  S S
KJr  S SKJr  S SKJr  \" 5       rSr S       SS jjr   S       SS jjr!SS jr" SS jr#SS jr$S S jr%S r&S!S jr'S!S jr(\S"S j5       r)\S#S j5       r*\S#S j5       r+g)$    )annotationsN)contextmanager)import_module)escapesub)AnyDict	GeneratorSequence)ObjectProxy)contexttrace)"_SUPPRESS_HTTP_INSTRUMENTATION_KEY_SUPPRESS_INSTRUMENTATION_KEY)extract)
StatusCode)TraceContextTextMapPropagatorsuppress_instrumentationc                    0 nU(       a  UR                  U5        U H!  n[        XS 5      nUc  M  [        U5      X4'   M#     U$ N)updategetattrstr)obj
attributesexisting	extractedattrvalues         v/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/opentelemetry/instrumentation/utils.pyextract_attributes_from_objectr!   0   sI     !#I"4(!%jIO      c                8   [        U [        5      (       d  [        R                  $ U S:  a  [        R                  $ U S::  a  [        R                  $ U S::  a  U(       a  [        R                  $ U S::  a  U(       a  [        R                  $ [        R                  $ )zqConverts an HTTP status code to an OpenTelemetry canonical status code

Args:
    status (int): HTTP status code
d   i+  i  i  )
isinstanceintr   UNSETERROR)statusallow_redirectserver_spans      r    http_status_to_status_coder,   =   sy     fc""|}}}r"   c                   [        U [        5      (       a,   U R                  SS5      u  p#[        U5      n [        XS5      n [        XS5      nU(       a?  [        U[        5      (       a)  [        US	5      (       a  [        XUR                  5        gggg! [         a  n[	        SU  S35      UeSnAff = f! [         a  n[	        SU SU S35      UeSnAff = f)
a9  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setattrr1   )r   r   module_path
class_nameexcmodulefuncs          r    unwrapr=   V   s     #s	&)jja&8#K
 {+	&-C 3d#D
4--'$2N2N4++, 3O-t  	 %<=	  	!*XfXQ?	s.   B B7 
B4B//B47
CCCc                V   S=n=px[         R                  " 5       [         R                  L a:  [        X4S9n[        R
                  " U5      n[         R                  R                  nO/[        R                  " 5       n[         R                  R                  nU R                  UUUUUS9n	X4$ )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_namerB   context_carriercontext_getterr   tokenctx	span_kindspans
             r    _start_internal_or_server_spanrS   s   s    0 #"E"C5#5#55o=s#NN))	!!#NN++	  D ;r"   c                    [        U [        [        45      (       d  U $ [        R                  R                  U 5      nUR                  SS5      $ )N%z%%)r%   r   bytesurllibparsequotereplace)squoteds     r    
_url_quoter]      s?    a#u&&\\"F
 >>#t$$r"   c                 4    0 n [         R                  U 5        U $ )zg
Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
OpenTelemetry execution context.
)
propagatorinject)_headerss    r    _get_opentelemetry_valuesrb      s      "HhOr"   c                8    [        [        U5       U S3SU 5      $ )Nz(?!$) )r   r   )python_path	directorypath_separators      r    _python_path_without_directoryrh      s*    9~.e4
 r"   c                     [         R                  " [        5      =(       d    [         R                  " [        5      (       + $ r   )r   	get_valuer   #_SUPPRESS_INSTRUMENTATION_KEY_PLAIN r"   r    is_instrumentation_enabledrm      s0    78 	B@A r"   c                 b    [        5       =(       a    [        R                  " [        5      (       + $ r   )rm   r   rj   r   rl   r"   r    is_http_instrumentation_enabledro      s'    %' 0A0A*1 - r"   c               '  0  #    [         R                  " 5       nU  H  n[         R                  " USU5      nM     [         R                  " U5      n Sv   U(       a  [         R                  " U5        gg! U(       a  [         R                  " U5        f f = f7f),Suppress instrumentation within the context.TN)r   rH   	set_valuerE   detach)keysrP   keyrO   s       r    _suppress_instrumentationrv      sq      


CT3/ NN3E"NN5! 5NN5! s   ABA3 B3 BBc               #  p   #    [        [        [        5         Sv   SSS5        g! , (       d  f       g= f7frq   N)rv   r   rk   rl   r"   r    r   r      s)      
#%'J
 	
 
 
s   6%	6
36c               #  f   #    [        [        5         Sv   SSS5        g! , (       d  f       g= f7frx   )rv   r   rl   r"   r    suppress_http_instrumentationrz      s      
##E	F 
G	F	Fs   1 	1
.1r   )r   r   r   zSequence[str]r   zDict[str, str] | NonereturnzDict[str, str])TF)r)   r&   r*   boolr+   r|   r{   r   )r   objectr   r   )r[   r   r{   r   )r{   zdict[str, Any])r{   r|   )rt   r   r{   Generator[None])r{   r~   ),
__future__r   urllib.parserW   
contextlibr   	importlibr   rer   r   typingr   r	   r
   r   wraptr   opentelemetryr   r   opentelemetry.contextr   r   opentelemetry.propagater   opentelemetry.tracer   ,opentelemetry.trace.propagation.tracecontextr   r_   rk   r!   r,   r=   rS   r]   rb   rh   rm   ro   rv   r   rz   rl   r"   r    <module>r      s   #  % #  1 1  ( , * +,
  $ LP
	
'
3H

    	2-F 'T% 
" 
"    r"   