
    i]                         S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	J
r
JrJrJrJrJrJr  S SKJrJrJrJr  S SKJr  \" S\S	9r " S
 S\R2                  5      r " S S\\\   5      rg)    N)abstractmethod)copy_context)partial)AnyCallableDictGenericListOptionalTupleTypeVar)	BaseModel
ConfigDictFieldPrivateAttr)BaseSpanT)boundc                      ^  \ rS rSrSr     SSS.S\\   S\\S\4      S	\\   S
\	\S4   S\\
\\4      S\\   SS4U 4S jjjjrSrU =r$ )Thread   ze
A wrapper for threading.Thread that copies the current context and uses the copy to run the target.
N )daemongrouptarget.nameargskwargsr   returnc                   > Ub(  [        U/UQ70 [        U[        5      (       a  UO0 D64nOSn[        TU ]  U[        5       R                  UUUS9  g )Nr   )r   r   r   r   r   )r   
isinstancedictsuper__init__r   run)selfr   r   r   r   r   r   	__class__s          h/home/james-whalen/.local/lib/python3.13/site-packages/llama_index_instrumentation/span_handlers/base.pyr$   Thread.__init__   sc     VVJvt4L4L&RTVD D>%% 	 	
    )NNNr   N)__name__
__module____qualname____firstlineno____doc__r   r   r   strr   r   boolr$   __static_attributes____classcell__r'   s   @r(   r   r      s      $/3" "+/
 "&
}
 #s(+,
 sm	

 CHo
 c3h(
 
 

 
r*   r   c                     ^  \ rS rSr% \" SS9r\" \SS9r\	\
\4   \S'   \" \SS9r\\   \S'   \" \SS9r\\   \S	'   \" 0 S
S9r\	\\\
   4   \S'   \" 5       r\\R.                     \S'   0 / / 0 4S\	\
\4   S\\   S	\\   S\	\\
4   4U 4S jjjr\S\
4S j5       r\S\R.                  4S j5       r   S#S\
S\R<                  S\\   S\\
   S\\	\
\4      S\SS4S jjr  S$S\
S\R<                  S\\   S\\   S\SS4S jjr   S$S\
S\R<                  S\\   S\\!   S\SS4S jjr"\#   S#S\
S\R<                  S\\   S\\
   S\\	\
\4      S\S\\   4S jj5       r$\#  S$S\
S\R<                  S\\   S\\   S\S\\   4S  jj5       r%\#  S$S\
S\R<                  S\\   S\\!   S\S\\   4S! jj5       r&S"r'U =r($ )%BaseSpanHandler.   T)arbitrary_types_allowedzDictionary of open spans.)default_factorydescription
open_spanszList of completed spans.completed_spansdropped_spansz&Id of current spans in a given thread.)defaultr:   current_span_ids_lockc                 4   > [         TU ]  UUUUS9  S U l        g )N)r;   r<   r=   r?   )r#   r$   r@   )r&   r;   r<   r=   r?   r'   s        r(   r$   BaseSpanHandler.__init__>   s,     	!+'-	 	 	
 
r*   r   c                     g)zClass name.r6   r   )clss    r(   
class_nameBaseSpanHandler.class_nameM   s     !r*   c                 h    U R                   c  [        R                  " 5       U l         U R                   $ )N)r@   	threadingLock)r&   s    r(   lockBaseSpanHandler.lockR   s$    ::")DJzzr*   Nid_
bound_argsinstance	parent_idtagsr   c                     XR                   ;   a  gU R                  UUUUUS9nU(       a$  U R                     XpR                   U'   SSS5        gg! , (       d  f       g= f)zLogic for entering a span.)rL   rM   rN   parent_span_idrP   N)r;   new_spanrJ   )r&   rL   rM   rN   rO   rP   r   spans           r(   
span_enterBaseSpanHandler.span_enterX   s]     //!==%!( ! D YY+/OOC( Y Ys   A
Aresultc                     U R                  XX4S9nU(       a#  U R                     U R                  U	 SSS5        gg! , (       d  f       g= f)zLogic for exiting a span.)rL   rM   rN   rW   N)prepare_to_exit_spanrJ   r;   )r&   rL   rM   rN   rW   r   rT   s          r(   	span_exitBaseSpanHandler.span_exitp   H     ((X ) 
 OOC(  	   <
A
errc                     U R                  XX4S9nU(       a#  U R                     U R                  U	 SSS5        gg! , (       d  f       g= f)z*Logic for dropping a span i.e. early exit.)rL   rM   rN   r^   N)prepare_to_drop_spanrJ   r;   )r&   rL   rM   rN   r^   r   rT   s          r(   	span_dropBaseSpanHandler.span_drop   r\   r]   rR   c                     g)z
Create a span.

Subclasses of BaseSpanHandler should create the respective span type T
and return it. Only NullSpanHandler should return a None here.
Nr   )r&   rL   rM   rN   rR   rP   r   s          r(   rS   BaseSpanHandler.new_span         	r*   c                     g)z
Logic for preparing to exit a span.

Subclasses of BaseSpanHandler should return back the specific span T
that is to be exited. If None is returned, then the span won't actually
be exited.
Nr   )r&   rL   rM   rN   rW   r   s         r(   rY   $BaseSpanHandler.prepare_to_exit_span   re   r*   c                     g)z
Logic for preparing to drop a span.

Subclasses of BaseSpanHandler should return back the specific span T
that is to be dropped. If None is returned, then the span won't actually
be dropped.
Nr   )r&   rL   rM   rN   r^   r   s         r(   r`   $BaseSpanHandler.prepare_to_drop_span   re   r*   )r@   )NNN)NN))r+   r,   r-   r.   r   model_configr   r"   r;   r   r0   r   __annotations__listr<   r
   r=   r?   r   r   r   r@   rH   rI   r$   classmethodrE   propertyrJ   inspectBoundArgumentsrU   rZ   BaseExceptionra   r   rS   rY   r`   r2   r3   r4   s   @r(   r6   r6   .   s   d;L$*E JS!V   %*D OT!W  #*DM47  27 H2d3-.  '2mE8INN#3 $&#%!#+-aL a Aw	
 sCx.  !3 ! ! inn   #'#')-00 **0 3-	0
 C=0 tCH~&0 0 
08 #' $)) **) 3-	)
 ) ) 
)( #''+)) **) 3-	)
 m$) ) 
)  
 #'(,)- ** 3-	
 ! tCH~&  
! " 
 #' $ ** 3-	
   
! " 
 #''+ ** 3-	
 m$  
! r*   r6   )ro   rH   abcr   contextvarsr   	functoolsr   typingr   r   r   r	   r
   r   r   r   pydanticr   r   r   r   %llama_index_instrumentation.span.baser   r   r   r6   r   r*   r(   <module>rx      sX       $  O O O > > :Cx 
Y 
>Vi Vr*   