o
    i                     @   sV   d dl mZ d dlZd dlmZ d dlmZ dd Zdeee ee f fdd	Z	dS )
    )OptionalN)core)Contextc                 C   sn   t j }tddjj}|d }d|v r!|d}|dd }n|d |dd }}| |t||f|||S )z
    Wrap `Executor` method used to submit a work executed in another
    thread. This wrapper ensures that a new `Context` is created and
    properly propagated using an intermediate function.
    zthreading.submit r   fn   N   )	ddtracetracercurrent_trace_contextr   dispatch_with_results
llmobs_ctxvaluepop_wrap_execution)funcargskwargscurrent_ctxr   selfr   fn_argsr   r   ^/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/futures/threading.py_wrap_submit   s   

r   ctxc                 C   sv   | d durt d| d f | d dur4tj| d  ||i |W  d   S 1 s/w   Y  ||i |S )aE  
    Intermediate target function that is executed in a new thread;
    it receives the original function with arguments and keyword
    arguments, including our tracing `Context`. The current context
    provider sets the Active context in a thread local storage
    variable because it's outside the asynchronous loop.
    r   Nzthreading.executionr   )r   dispatchr	   r
   _activate_context)r   r   r   r   r   r   r   r      s    r   )
typingr   r	   ddtrace.internalr   ddtrace.tracer   r   tupler   r   r   r   r   <module>   s    "