o
    i
                     @  s   d dl m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 z$d dlmZmZ ejaejad'd	d
Zd(ddZd)ddZd*ddZW n eyV   d'dd
ZY nw d+d!d"Zd,d$d%Zd&S )-    )annotations)asdict)partial)AnyCallable)ContextCarrierattach_contextget_context)ProcessPoolExecutorThreadPoolExecutorreturnNonec                   C  s(   t jtu rtt _tjtu rtt_dS dS )zMonkey-patch `submit()` methods of `ThreadPoolExecutor` and `ProcessPoolExecutor`
        to carry over OTEL context across threads and processes.
        N)r   submitsubmit_t_origsubmit_tr
   submit_p_origsubmit_p r   r   n/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/integrations/executors.pyinstrument_executors   s
   


r   sr   fnCallable[..., Any]argsr   kwargsc                O  s.   t |g|R i |}t }t| t||ddS )z[A wrapper around ThreadPoolExecutor.submit() that carries over OTEL context across threads.Ncarrierfuncparent_config)r   r	   r   _run_with_contextr   r   r   r   r   r   r   r   r      s   r   r
   c                O  s0   t |g|R i |}t }t| t||t dS )z^A wrapper around ProcessPoolExecutor.submit() that carries over OTEL context across processes.r   )r   r	   r   r   serialize_configr    r   r   r   r   !   s   r   r   r   r   Callable[[], Any]r   dict[str, Any] | Nonec                 C  sB   |durt | t|  | W  d   S 1 sw   Y  dS )zA wrapper around a function that restores OTEL context from a carrier and then calls the function.

        This gets run from within a process / thread.
        N)deserialize_configr   r   r   r   r   r   '   s
   
$r   c                   C  s   d S )Nr   r   r   r   r   r   6   s   dict[str, Any]c                  C  s   ddl m}  t| S )N   GLOBAL_CONFIG)configr(   r   r'   r   r   r   r!   :   s   r!   r)   c                 C  s,   ddl m}m} |js|di |  d S d S )Nr&   )r(   	configurer   )r)   r(   r*   _initialized)r)   r(   r*   r   r   r   r$   C   s   r$   N)r   r   )r   r   r   r   r   r   r   r   )r   r
   r   r   r   r   r   r   )r   r   r   r"   r   r#   r   r   )r   r%   )r)   r%   r   r   )
__future__r   dataclassesr   	functoolsr   typingr   r   logfire.propagater   r   r	   concurrent.futuresr
   r   r   r   r   r   r   r   r   ImportErrorr!   r$   r   r   r   r   <module>   s$    




	