
    g
                        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 	 d dlmZmZ ej                   aej                   addZddZdd	Zdd
ZddZddZy# e$ r ddZY w xY w)    )annotations)asdict)partial)AnyCallable)ContextCarrierattach_contextget_context)ProcessPoolExecutorThreadPoolExecutorc                     t         j                  t        u rt        t         _        t        j                  t
        u rt        t        _        yy)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     ]/var/www/openai/venv/lib/python3.12/site-packages/logfire/_internal/integrations/executors.pyinstrument_executorsr      s7    
 $$5(0%%%6)1& 7r   c               \    t        |g|i |}t               }t        | t        ||d      S )z[A wrapper around ThreadPoolExecutor.submit() that carries over OTEL context across threads.Ncarrierfnparent_config)r   r
   r   _run_with_contextsr   argskwargsr   s        r   r   r      s2    R)$)&)-Q 17rY]^^r   c               l    t        |g|i |}t               }t        | t        ||t	                     S )z^A wrapper around ProcessPoolExecutor.submit() that carries over OTEL context across processes.r   )r   r
   r   r   serialize_configr   s        r   r   r   !   s5    R)$)&)-Q 17rYiYkllr   c                l    |t        |       t        |       5   |       cddd       S # 1 sw Y   yxY w)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   s      r   r   r   '   s+    
 $}-G$4 %$$s   *3c                      y )Nr   r   r   r   r   r   4   s    r   c                 $    ddl m}  t        |       S )N   GLOBAL_CONFIG)configr)   r   r(   s    r   r"   r"   8   s    &
 -  r   c                >    ddl m}m} |j                  s	 |di |  y y )Nr'   )r)   	configurer   )r*   r)   r,   _initialized)r*   r)   r,   s      r   r$   r$   A   s    1%%F &r   N)returnNone)r   r   r   Callable[..., Any]r   r   r    r   )r   r   r   r0   r   r   r    r   )r   r   r   zCallable[[], Any]r   zdict[str, Any] | Noner.   r   )r.   dict[str, Any])r*   r1   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   <module>r9      sn    "     I I, K&--M'..M2_m	"!  s   0A 	A+*A+