o
    i                     @   s   d dl mZ d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ d d	lmZ d d
lmZ defddZdeeef fddZdddZdddZdedeegef fddZdS )    )Any)CallableN)config)	SPAN_KIND)trace_utils)SpanKind)	SpanTypes)Config)tracerreturnc                   C   s
   t tjS )N)strdramatiq__version__ r   r   [/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/dramatiq/patch.pyget_version   s   
r   c                   C   s   ddiS )Nr   z>=1.10.0r   r   r   r   r   _supported_versions   s   r   c                   C   s.   t tddrdS dt_tddttj dS )zM
    Instrument dramatiq so any new Actor is automatically instrumented.
    __datadog_patchFNTr   zActor.send_with_options)getattrr   r   r   wrap"_traced_send_with_options_functionr   r   r   r   r   patch   s   r   c                   C   s(   t tddsdS dt_ttjd dS )zE
    Disconnect remove tracing capabilities from dramatiq Actors
    r   FNsend_with_options)r   r   r   r   unwrapActorr   r   r   r   unpatch"   s   r   integration_configc                    sH   dt tgtf dtjdtt dtttf dt tgtf f
 fdd}|S )a  
    NOTE: This accounts for both the send() and send_with_options() methods,
    since send() just wraps around send_with_options() with empty options.

    In terms of expected behavior, this traces the send_with_options() calls,
    but does not reflect the actual execution time of the background task
    itself. The duration of this span is the duration of the send_with_options()
    call itself.
    funcinstanceargskwargsr   c              	      sj   t jdtjtjd  dd}|ttj	d|j
d|ji | |i |W  d    S 1 s.w   Y  d S )Nz dramatiq.Actor.send_with_options)pin
int_config)	span_typeservicez
actor.namezactor.options)r
   tracer   WORKERr   ext_serviceset_tagsr   r   PRODUCER
actor_nameoptions)r   r   r   r    spanr   r   r   _traced_send_with_options8   s   $zE_traced_send_with_options_function.<locals>._traced_send_with_options)r   r   r   r   tupledict)r   r.   r   r-   r   r   -   s   
r   )r   N)typingr   r   r   ddtracer   ddtrace.constantsr   ddtrace.contribr   ddtrace.extr   r   !ddtrace.internal.settings._configr	   ddtrace.tracer
   r   r   r0   r   r   r   r   r   r   r   r   <module>   s    

 