
    	h,                       d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZ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 d dlmZ d dlmZ d dlmZ d d	lmZm Z m!Z!m"Z" d d
l#m$Z$m%Z%m&Z& erd dl'm(Z( d dl)m*Z*  ej+        d          Z, ej-         e            dz            Z.dEdZ/ej0         G d d                      Z1	 dFdGd Z2	 dHdId(Z3dJd,Z4	 	 dKdLd1Z5	 	 dKdMd2Z6	 dNdOd3Z7dPd4Z8dQd6Z9dRd:Z:dSd<Z;dTd?Z<	 dUdVdCZ=dWdDZ>dS )X    )annotationsN)	cpu_count)EmptyQueue)TYPE_CHECKINGOptionalUnioncast)schemas)utils)CompressedTraces)_AUTO_SCALE_DOWN_NEMPTY_TRIGGER_AUTO_SCALE_UP_NTHREADS_LIMIT_AUTO_SCALE_UP_QSIZE_TRIGGER	_BOUNDARY)SerializedFeedbackOperationSerializedRunOperation#combine_serialized_queue_operations)Context)Clientzlangsmith.client   max_workersbatchlist[TracingQueueItem]returnAdict[tuple[Optional[str], Optional[str]], list[TracingQueueItem]]c                    ddl m}  |t                    }| D ]+}|j        |j        f}||                             |           ,|S )z4Group batch items by (api_url, api_key) combination.r   )defaultdict)collectionsr   listapi_urlapi_keyappend)r   r   groupeditemkeys        s/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/langsmith/_internal/_background_thread.py_group_batch_by_api_endpointr)   .   sb     ('''''k$G " "|T\*D!!!!N    c                  j    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   dZ	 	 	 dddZddZddZdS )TracingQueueItemzAn item in the tracing queue.

    Attributes:
        priority (str): The priority of the item.
        item (Any): The item itself.
        otel_context (Optional[Context]): The OTEL context of the item.
    strpriority:Union[SerializedRunOperation, SerializedFeedbackOperation]r&   Optional[str]r"   r#   Optional[Context]otel_contextr.   r&   r#   r"   r2   Nr   Nonec                L    || _         || _        || _        || _        || _        d S Nr3   )selfr.   r&   r#   r"   r2   s         r(   __init__zTracingQueueItem.__init__M   s.     !	(r*   otherboolc                R    | j         | j        j        f|j         |j        j        fk     S r6   )r.   r&   	__class__r7   r9   s     r(   __lt__zTracingQueueItem.__lt__[   s-    ty23NJ 7
 
 	
r*   objectc                |    t          |t                    o'| j        | j        j        f|j        |j        j        fk    S r6   )
isinstancer,   r.   r&   r<   r=   s     r(   __eq__zTracingQueueItem.__eq__a   sB    %!122 4MI8
 nej2384 	4r*   )NNN)r.   r-   r&   r/   r#   r0   r"   r0   r2   r1   r   r4   )r9   r,   r   r:   )r9   r?   r   r:   )	__name__
__module____qualname____doc____annotations__	__slots__r8   r>   rB    r*   r(   r,   r,   ;   s           MMMDDDD####JI "&!%*.) ) ) ) )
 
 
 
4 4 4 4 4 4r*   r,   d   Ttracing_queuer   limitintblockr:   max_size_bytesc                   g }d}	 |                      |d          x}r?|                    |           |dk    r$||j                                        z  }||k    r|S 	 	 |                      |d          }n# t          $ r Y nYw xY w|                    |           |dk    r#||j                                        z  }||k    rn|rt          |          |k    rn~n# t          $ r Y nw xY w|S )Nr   g      ?)rN   timeoutT皙?)getr$   r&   calculate_serialized_sizer   len)rK   rL   rN   rO   
next_batchcurrent_sizer&   s          r(   _tracing_thread_drain_queuerX   h   sW    *,JL$ !$$5$$???4 	&d###!!	 C C E EE.00%%	$((ud(CC    d### !!	 C C E EE  .00  ZE11'	(    s=   AC C  A8 7C 8
BC BAC 
C+*C+  @clientr   
size_limitsize_limit_bytes
int | None6tuple[Optional[io.BytesIO], Optional[tuple[int, int]]]c                ,   	 | j         dS | j         j        5  | j         j        }| j        p|}||dk    rt	          d|           ||dk     rt	          d|           |||k     r || j         j        |k     r	 d d d            dS | j         j                            dt           d	                                           | j         j        
                                 | j         j                                        }| j         j        }| j         j        |_        ||f}| j                                          d d d            n# 1 swxY w Y   |                    d           ||fS # t"          $ r  t$                              dd	           Y dS w xY w)
N)NNr   z!size_limit must be positive; got z*size_limit_bytes must be nonnegative; got z--z--
uLangSmith tracing error: Failed to submit trace data.
This does not affect your application's runtime.
Error details:Texc_info)compressed_traceslockuncompressed_size_max_batch_size_bytes
ValueErrortrace_countcompressor_writerwriter   encodeclosebuffertell_contextcontextresetseek	Exceptionloggererror)rZ   r[   r\   pre_compressed_sizerW   filled_buffercompressed_traces_infos          r(   '_tracing_thread_drain_compressed_bufferry      sJ   /#+:%* 	- 	-"(":"L%;O?O%*// !QZ!Q!QRRR+0@10D0D SAQSS  
 !(,?BR,R,R"f&>&JZ&W&W!#	- 	- 	- 	- 	- 	- 	- 	-( $6<<&Y&&&--//   $6<<>>>!3:??AAL"4;M$*$<$EM!&9<%H"$**,,,?	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-B 	1566 	 	 	 	 	 	
 	
 	
 zz	sG   E) E) A%E<E) 	B0E9E) E		E) E	E) )&FFbatch_to_processlist[tuple[str, dict]]r4   c                   	 d |D             }d |D             }| j         t          d          t          |                      |                    }t          |          t          |          k    r/t	          dt          |           dt          |                     d |D             }||k    rt	          d| d|           t          ||          D ]?\  \  }}}|d	k    r|                     |           $|d
k    r|                     |           @| j        r| j        	                                 dS dS # t          $ r  t                              dd           Y dS w xY w)z1Process a batch of run operations asynchronously.c                    g | ]\  }}|S rI   rI   ).0_run_datas      r(   
<listcomp>z3_process_buffered_run_ops_batch.<locals>.<listcomp>   s    BBB+!XXBBBr*   c                8    g | ]}|                     d           S idrS   r~   runs     r(   r   z3_process_buffered_run_ops_batch.<locals>.<listcomp>   s"    ;;;#;;;r*   NzAprocess_buffered_run_ops should not be None when processing batchzGprocess_buffered_run_ops must return the same number of runs. Expected z, got c                8    g | ]}|                     d           S r   r   r   s     r(   r   z3_process_buffered_run_ops_batch.<locals>.<listcomp>   s"    AAA3AAAr*   zKprocess_buffered_run_ops must preserve run IDs in the same order. Expected postpatchzLangSmith buffered run ops processing error: Failed to process batch.
This does not affect your application's runtime.
Error details:Tra   )_process_buffered_run_opsRuntimeErrorr!   rU   rg   zip_create_run_update_run_data_available_eventsetrs   rt   ru   )	rZ   rz   	run_dictsoriginal_idsprocessed_runsprocessed_ids	operationr   processed_runs	            r(   _process_buffered_run_ops_batchr      s	   +
BB1ABBB	;;;;; +3S   f>>yIIJJ ~#i..00H	NNH H25n2E2EH H  
 BA.AAAL((@(@ @0=@ @   .11A>-R-R 	2 	2)NYMF""""=1111g%%""=111 ' 	/(,,.....	/ 	/ 
 
 
 	 	 	
 	
 	
 	
 	
 	

s   D6D< <&E&%E&use_multipartmark_task_doneopsJOptional[list[Union[SerializedRunOperation, SerializedFeedbackOperation]]]c                   	 t          |          }|                                D ]\  \  }}}	|st          d |	D                       }
nd |	D             fd|D             }
|r|                     |
||           Yt	          d |
D                       r&t
                              d           d |
D             }
|                     t          t          t                   |
          ||           n,# t          $ r t
                              dd	
           Y nw xY w|rc|c|D ]b}	 |                                 # t          $ r:}dt          |          v rt
                              d|            n Y d}~Wd}~ww xY wdS dS dS # |rc|b|D ]`}	 |                                 # t          $ r:}dt          |          v rt
                              d|            n Y d}~Wd}~ww xY ww w w xY w)a  Handle a batch of tracing queue items by sending them to LangSmith.

    Args:
        client: The LangSmith client to use for sending data.
        tracing_queue: The queue containing tracing items (used for task_done calls).
        batch: List of tracing queue items to process.
        use_multipart: Whether to use multipart endpoint for sending data.
        mark_task_done: Whether to mark queue tasks as done after processing.
            Set to False when called from parallel execution to avoid double counting.
        ops: Pre-combined serialized operations to use instead of combining from batch.
            If None, operations will be combined from the batch items.
    c                    g | ]	}|j         
S rI   r&   r~   r&   s     r(   r   z0_tracing_thread_handle_batch.<locals>.<listcomp>  s    7774TY777r*   c                &    h | ]}|j         j        S rI   )r&   r   r   s     r(   	<setcomp>z/_tracing_thread_handle_batch.<locals>.<setcomp>  s    BBBdTY\BBBr*   c                &    g | ]}|j         v |S rI   r   )r~   op	group_idss     r(   r   z0_tracing_thread_handle_batch.<locals>.<listcomp>  s%    DDDB)1C1CR1C1C1Cr*   )r"   r#   c              3  @   K   | ]}t          |t                    V  d S r6   rA   r   r~   r   s     r(   	<genexpr>z/_tracing_thread_handle_batch.<locals>.<genexpr>%  s-      WWrz"&ABBWWWWWWr*   z;Feedback operations are not supported in non-multipart modec                <    g | ]}t          |t                    |S rI   r   r   s     r(   r   z0_tracing_thread_handle_batch.<locals>.<listcomp>)  s9     ! ! !)".IJJ!! ! !r*   r`   Tra   N!task_done() called too many times3Ignoring harmless task_done error during shutdown: )r)   itemsr   _multipart_ingest_opsanyrt   warning_batch_ingest_run_opsr
   r!   r   rs   ru   	task_donerg   r-   debug)rZ   rK   r   r   r   r   grouped_batchesr"   r#   group_batch	group_opsr   er   s                @r(   _tracing_thread_handle_batchr      s4   ,56u==/>/D/D/F/F 	 	+Wg E?77;777 		 CBkBBB	DDDD#DDD	 ,,w -     WWYWWWWW NNU  ! !"+! ! !I
 ,,45yAA## -    /	:  
 
 
 	 	 	
 	
 	
 	
 	

  	m7  
!++----!   :c!ffDD URSUU    	    			 	77   	m7  
!++----!   :c!ffDD URSUU    	    			7sl   C2C6 5F 6&DF DF +E  
F
0E??F	G6F,+G6,
G0	60G+	&G6+G0	0G6c                   	 |t          d |D                       }d |D             }d |D             }|r=| j        | j                            ||           nt                              d           n,# t
          $ r t                              dd           Y nw xY w|rc|c|D ]b}	 |                                 # t          $ r:}d	t          |          v rt          	                    d
|            n Y d}~Wd}~ww xY wdS dS dS # |rc|b|D ]`}	 |                                 # t          $ r:}d	t          |          v rt          	                    d
|            n Y d}~Wd}~ww xY ww w w xY w)ad  Handle a batch of tracing queue items by exporting them to OTEL.

    Args:
        client: The LangSmith client containing the OTEL exporter.
        tracing_queue: The queue containing tracing items (used for task_done calls).
        batch: List of tracing queue items to process.
        mark_task_done: Whether to mark queue tasks as done after processing.
            Set to False when called from parallel execution to avoid double counting.
        ops: Pre-combined serialized operations to use instead of combining from batch.
            If None, operations will be combined from the batch items.
    Nc                    g | ]	}|j         
S rI   r   r   s     r(   r   z5_otel_tracing_thread_handle_batch.<locals>.<listcomp>a  s    6S6S6STty6S6S6Sr*   c                <    g | ]}t          |t                    |S rI   )rA   r   r   s     r(   r   z5_otel_tracing_thread_handle_batch.<locals>.<listcomp>c  s(    NNN"z"6L'M'MN2NNNr*   c                f    i | ].}t          |j        t                    |j        j        |j        /S rI   )rA   r&   r   r   r2   r   s     r(   
<dictcomp>z5_otel_tracing_thread_handle_batch.<locals>.<dictcomp>d  sD     
 
 
$)%;<<
IL$+
 
 
r*   zLangSmith tracing error: Failed to submit OTEL trace data.
This does not affect your application's runtime.
Error details: client.otel_exporter is NonezpOTEL tracing error: Failed to submit trace data.
This does not affect your application's runtime.
Error details:Tra   r   r   )
r   otel_exporterexport_batchrt   ru   rs   r   rg   r-   r   )	rZ   rK   r   r   r   run_opsotel_context_mapr   r   s	            r(   !_otel_tracing_thread_handle_batchr   K  s|   ((;56S6SU6S6S6STTCNNNNN
 

 
 

  	#/$11';KLLLLB    
 
 
 	 	 	
 	
 	
 	
 	

  	m7  
!++----!   :c!ffDD URSUU    	    			 	77   	m7  
!++----!   :c!ffDD URSUU    	    			7sl   A2A5 4D 5&BD BD *B??
D	0C>>D	E5D+*E5+
E/	50E*	%E5*E/	/E5c           
     \   t          d |D                       }t          j        |          }t          j        |          }	 t          j        d          5 }|                    t          | |||d|          }	|                    t          | ||d|          }
|	                                 |
                                 ddd           n# 1 swxY w Y   nk# t          $ r^}dt          |          v rBt                              d           t          | |||d|           t          | ||d|           n Y d}~nd}~ww xY w|rc|c|D ]b}	 |                                 # t          $ r:}dt          |          v rt                              d	|            n Y d}~Wd}~ww xY wdS dS dS )
a  Handle a batch of tracing queue items by sending to both both LangSmith and OTEL.

    Args:
        client: The LangSmith client to use for sending data.
        tracing_queue: The queue containing tracing items (used for task_done calls).
        batch: List of tracing queue items to process.
        use_multipart: Whether to use multipart endpoint for LangSmith.
        mark_task_done: Whether to mark queue tasks as done after processing.
            Set to False primarily for testing when items weren't actually queued.
    c                    g | ]	}|j         
S rI   r   r   s     r(   r   z7_hybrid_tracing_thread_handle_batch.<locals>.<listcomp>  s    .K.K.KTty.K.K.Kr*      r   FNz6cannot schedule new futures after interpreter shutdownz@Interpreter shutting down, falling back to sequential processingr   r   )r   copydeepcopycfThreadPoolExecutorsubmitr   r   resultr   r-   rt   r   r   rg   )rZ   rK   r   r   r   r   langsmith_opsotel_opsexecutorfuture_langsmithfuture_otelr   r   s                r(   #_hybrid_tracing_thread_handle_batchr     s   $ ..K.KU.K.K.K
L
LC M#&&M}S!!H'"q111 	!X',    #//1 K ##%%%   -	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!.    Cs1vvMM LLR   )umUM   .ueX    	    "  -3 	 	A
''))))   6#a&&@@ LLQaQQ    	    		 33	 	sV   C A(C C CC CC 
E "AD;;E E!!
F%+0F  F%c                   t          | d          r| j        dS 	 t          j        t          j        d                    sdS ddlm} |                                }t          |d          rTt          |j        d          r?|j        j	        
                    d	d          }t                              d
|            |S dS # t          $ r)}t                              d| d           Y d}~dS d}~ww xY w)zCheck if client is using LangSmith's internal OTLP provider.

    Returns True if using LangSmith's internal provider, False if user
    provided their own.
    r   NFOTEL_ENABLEDr   )traceresource
attributeszlangsmith.internal_providerz;TracerProvider resource check: langsmith.internal_provider=z)Could not determine TracerProvider type: z, assuming user-provided)hasattrr   ls_utils	is_truishget_env_varopentelemetryr   get_tracer_providerr   r   rS   rt   r   rs   )rZ   r   tracer_provideris_internalr   s        r(    _is_using_internal_otlp_providerr     sH    6?++ v/C/Ku !("6~"F"FGG 	5 	('''''3355?J// 
	G$l5
 5
 
	 *2=AA-u K LL=/:= =   u   SSSS	
 	
 	
 uuuuu	s   &C A=C 
C6C11C6Optional[int]c                     t          j        d          } | >	 t          |           S # t          $ r! t                              d|  d           Y nw xY wd S )NBATCH_INGEST_SIZE_LIMITz+Invalid value for BATCH_INGEST_SIZE_LIMIT: z, continuing with default)r   r   rM   rg   rt   r   )size_limit_strs    r(   get_size_limit_from_envr     s    )! N !	~&&& 	 	 	NN*n * * *    	
 4s   ' (AAinfols_schemas.LangSmithInfols_schemas.BatchIngestConfigc                    t          j        dd dt          t          t                    }| s|S 	 | j        s|S t                      }|
|| j        d<   | j        S # t          $ r |cY S w xY w)NFrJ   )use_multipart_endpointr\   r[   scale_up_nthreads_limitscale_up_qsize_triggerscale_down_nempty_triggerr[   )
ls_schemasBatchIngestConfigr   r   r   batch_ingest_configr   BaseException)r   default_configenv_size_limits      r(   _ensure_ingest_configr     s      1$ =;"A  N  ' 	"!!022%5CD$\2''   s   A  A A('A(tuple[bool, bool]c                     t          j        t          j        d                    } t          j        t          j        d                    }| sdS | }|}||fS )an  Get the current tracing mode configuration.

    Returns:
        tuple[bool, bool]:
            - hybrid_otel_and_langsmith: True if both OTEL and LangSmith tracing
              are enabled, which is default behavior if OTEL_ENABLED is set to
              true and OTEL_ONLY is not set to true
            - is_otel_only: True if only OTEL tracing is enabled
    r   	OTEL_ONLY)FF)r   r   r   )otel_enabled	otel_onlyhybrid_otel_and_langsmithis_otel_onlys       r(   get_tracing_moder   )  sa     %h&:>&J&JKKL"8#7#D#DEEI  |$-L$l22r*   
client_refweakref.ref[Client]c                L    |             d S j         }|J t          j                  }|d         }|d         }|d         }|                    dd          }g dt	          j        t	          j        d                    pj        d u}|s|rŉj        j        pi                     dd          st          
                    d	           nt          j                    _        t                      _        t!          j                    _        t!          j        t(          t          j                  f
                                           dz  dfd} |            r:D ]+}	|	                                s                    |	           ,t3                    |k     rp|                                |k    rXt!          j        t6          t          j                  |f
          }
                    |
           |
                                 t;                      \  }}j        p|                    d          pd}t?          |||          x}r;|rtA          |||           n&|rtC          ||           ntE          |||            |            :t;                      \  }}j        p|                    d          pd}t?          ||d|          x}r|r-t          #                    d           tA          |||           nZ|r,t          #                    d           tC          ||           n,t          #                    d           tE          |||           t?          ||d|          x}t          #                    d           d S )Nr[   r   r   r   Fr   DISABLE_RUN_COMPRESSIONzstd_compression_enabledz~Run compression is not enabled. Please update to the latest version of LangSmith. Falling back to regular multipart ingestion.)targetargs   r   r:   c                    rt          d          r#j        rt                              d           dS t	          j                                                    st                              d           dS t          t          d          rFt          j                  t                    z   k    } | st                              d           | S dS )N_manual_cleanupz3Client is being cleaned up, stopping tracing threadFz,Main thread is dead, stopping tracing threadgetrefcountzeClient refs count indicates we're the only remaining reference to the client, stopping tracing threadT)
r   r  rt   r   	threadingmain_threadis_alivesysr  rU   )should_keep_threadrZ   num_known_refssub_threadss    r(   keep_thread_activez7tracing_control_thread_func.<locals>.keep_thread_activeh  s     	F-..	393I	 LLNOOO5$&&//11 	LLGHHH53&& 	 "%!8!8>CM M < " & =   &% 4r*   r\   r   rL   rO   rL   rN   rO   zHybrid mode cleanupOTEL-only cleanupLangSmith-only cleanupz'Tracing control thread is shutting downr   r:   )$rK   r   r   rS   r   r   r   r   instance_flagsrt   r   weakrefWeakSet_futuresr   rc   r  Eventr   Thread-tracing_control_thread_func_compress_parallelrefstartr	  removerU   qsize_tracing_sub_thread_funcr$   r   rf   rX   r   r   r   r   )r   rK   r   r[   r   r   r   disable_compressionr  thread
new_threadr   r   max_batch_sizerV   rZ   r  r  s                  @@@r(   tracing_control_thread_funcr$  @  s   Z\\F~(M$$$/<<),7J#67P#Q"56N"O'++,DeLLM*,KN 	8/0IJJKK 	,t+    =  *0b55&
 
 	  NNU   
 &o//FO'7'9'9F$+4?+<+<F(Dk&))+   egggaN       < 


 $! 	+ 	+F??$$ +""6***666##%%(>>>")/k&))=9  J z***2B2D2D/!<( "&&'9:: 	
 5N
 
 
 
: 	 ) 3M:}     1&-TTTT -M:}  E 


 $N /?.@.@+|$X(;(?(?@R(S(SXWX  4Zu^   *  % 	LL.////z=     		LL,----fmZPPPP LL1222(z=  ! 4Zu^   * & LL:;;;;;r*         ?flush_intervalfloatc                    |             d S t                               d           j        j        j        t                               d           d S t          j                  }|d         }j        p|	                    dd          }ddfd	}t          j                    }	 j                            d          } |            snJ|rj                                         t          ||          \  }}	|c	 t                              j        ||	          }
j                            |
           n&# t&          $ r                     ||	           Y nw xY wt          j                    }nt          j                    |z
  |k    rt          dd          \  }}	|\	 t)          j        t                              j        ||	          g           n&# t&          $ r                     ||	           Y nw xY wt          j                    }q	 t          dd          \  }}	|\	 t)          j        t                              j        ||	          g           n&# t&          $ r                     ||	           Y nw xY wn,# t*          $ r t                               dd
           Y nw xY wt                               d           d S )Nz4Tracing control thread func compress parallel calledzLangSmith tracing error: Required compression attributes not initialized.
This may affect trace submission but does not impact your application's runtime.r[   r\   rY      r   r:   c                    rt          d          r#j        rt                              d           dS t	          j                                                    st                              d           dS t          t          d          r6t          j                  k    } | st                              d           | S dS )Nr  z7Client is being cleaned up, stopping compression threadFz0Main thread is dead, stopping compression threadr  ziClient refs count indicates we're the only remaining reference to the client, stopping compression threadT)	r   r  rt   r   r  r  r	  r
  r  )r  rZ   r  s    r(   r  zItracing_control_thread_func_compress_parallel.<locals>.keep_thread_active  s     	F-..	393I	 LLRSSS5$&&//11 	LLKLLL53&& 	 "%!8!8>!I% A   &% 4r*   TrR   )rQ   r  )r[   r\   zuLangSmith tracing error: Failed during final cleanup.
This does not affect your application's runtime.
Error details:ra   z1Compressed traces control thread is shutting downr  )rt   r   rc   r   r  ru   r   r   rf   rS   time	monotonicwaitclearry   LANGSMITH_CLIENT_THREAD_POOLr   _send_compressed_multipart_reqaddr   r   rs   )r   r&  r   r[   r\   r  last_flush_time	triggereddata_streamrx   futurefinal_data_streamrZ   r  s               @@r(   r  r    s    Z\\F~
LLGHHH ('/?"1	
 	
 	

 	/<<),7J3 7J7N7NJ8 8
 N      4 n&&O43055d5CC	!!## 	  .	3(..000 8j"234 34/K/ &9@@=#. F
 O''////#   99#.    
 #n..OO   ?2~EE <q1  * * < C C$*$I$/$:!" !"    (   =='2    
 #'."2"2i43n
 4q1
 
 
	
" (4;;"A-2         55%*      
 
 
 	 	 	
 	
 	
 	
 	

 LLDEEEEEsZ   ;E  E*)E*34G( ( H
H$J <4I1 0J 1 JJ JJ &K Kc                    |             }|d S 	 |j         sd S n3# t          $ r&}t                              d|           Y d }~d S d }~ww xY w|j        }|J t          |j                   }|                    dd          }d}t          j                    	                                r||d         k    r|j
        p|                    d          pd}t          |||          x}	rOd}t                      \  }
}|
rt          |||	|           n,|rt          |||	           nt          |||	|           n|dz  }t          j                    	                                r||d         k    t                      \  }
}|j
        p|                    d          pd}t          ||d	|
          x}	r|
rt          |||	|           nZ|r,t                              d           t          |||	           n,t                              d           t          |||	|           t          ||d	|
          x}	t                              d           d S )Nz#Error in tracing control thread: %sr[   rJ   r   r   r\   r  r  Fr  r  r  z+Tracing control sub-thread is shutting down)r   r   rt   r   rK   r   rS   r  r  r	  rf   rX   r   r   r   r   )r   r   rZ   r   rK   r   r[   seen_successive_empty_queuesr#  rV   r   r   s               r(   r  r  X  s6    Z\\F~{ 	F	   :A>>> (M$$$/<<$((s;;J#$ 
 	((** . ):;< < ( "&&'9:: 	
 5N
 
 
 
: 	. ,-(6F6H6H3%|( 3M:}     1&-TTTT -M:}    )A-(= 	((** . ):;< <> /?.@.@+|$X(;(?(?@R(S(SXWX  4Zu^   *  % 	/z=     		LL,----fmZPPPP LL1222(z=   4Zu^   * $ LL>?????s    
A
AA
)r   r   r   r   )rJ   Tr   )
rK   r   rL   rM   rN   r:   rO   rM   r   r   )rJ   rY   )rZ   r   r[   rM   r\   r]   r   r^   )rZ   r   rz   r{   r   r4   )TN)rZ   r   rK   r   r   r   r   r:   r   r:   r   r   r   r4   )rZ   r   rK   r   r   r   r   r:   r   r   r   r4   )T)rZ   r   rK   r   r   r   r   r:   r   r:   r   r4   )rZ   r   r   r:   )r   r   )r   r   r   r   )r   r   )r   r   r   r4   )r%  )r   r   r&  r'  r   r4   )r   r   r   r:   r   r4   )?
__future__r   concurrent.futuresfuturesr   r   	functoolsiologgingr
  r  r+  r  multiprocessingr   queuer   r   typingr   r   r	   r
   	langsmithr   r   r   r   &langsmith._internal._compressed_tracesr   langsmith._internal._constantsr   r   r   r   langsmith._internal._operationsr   r   r   opentelemetry.context.contextr   langsmith.clientr   	getLoggerrt   r   r/  r)   total_orderingr,   rX   ry   r   r   r   r   r   r   r   r   r$  r  r  rI   r*   r(   <module>rJ     s   " " " " " "            				  



       % % % % % %                    , + + + + + ' ' ' ' ' ' C C C C C C                      (555555''''''		-	.	.4r4qQQQ 
 
 
 
 )4 )4 )4 )4 )4 )4 )4 )4Z WX+ + + + +^ KU2 2 2 2 2j/
 /
 /
 /
n   	K K K K Kd   	< < < < <H  N N N N Nb$ $ $ $N      03 3 3 3.D< D< D< D<P >ANF NF NF NF NFbM@ M@ M@ M@ M@ M@r*   