o
    i"                     @   s\  d dl mZ d dlm  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 dlmZ d d	lmZ d d
lmZ ddlmZ ddlmZ e
deedeedddeedddd de fddZ!dee e f fddZ"dd Z#dd Z$dd Z%dd  Z&d!d" Z'd#d$ Z(d%d& Z)d'd( Z*d)d* Z+d+d, Z,d-d. Z-d/d0 Z.dS )1    N)wrap_function_wrapper)config)Pin)unwrap)azure_eventhubs)schematize_service_name)_get_config)get_argument_value)asbool   )create_context)dispatch_message_modifierr   &DD_AZURE_EVENTHUBS_DISTRIBUTED_TRACINGT)default,DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED)_default_servicedistributed_tracingbatch_linksreturnc                   C   s   t tddS )N__version__ )getattrazure_eventhub r   r   b/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/azure_eventhubs/patch.pyget_version   s   r   c                   C   s   ddiS )Nazure.eventhubz>=5.12.0r   r   r   r   r   _supported_versions    s   r   c                  C      t tfD ]} t|  qd S N)r   azure_eventhub_aio_patchazure_eventhubs_moduler   r   r   patch$      
r$   c                 C   s   t | ddrdS d| _| jdkr=t | j tddt tddt tddt	 tdd	t
 tdd
t	 tddt
 dS t | j t | j tddt tddt tddt tddt tdd	t tdd
t tddt dS )z4
    Patch `azure.eventhub` modules for tracing
    _datadog_patchFNTzazure.eventhub.aiozEventHubProducerClient.__init__z#EventHubProducerClient.create_batchz!EventHubProducerClient.send_eventz!EventHubProducerClient.send_batchz+EventHubProducerClient._buffered_send_eventz+EventHubProducerClient._buffered_send_batchr   zEventDataBatch.add)r   r&   __name__r   ontoEventHubProducerClient_w_patched_producer_init_patched_create_batch_async_patched_send_event_async_patched_send_batch_asyncEventDataBatch_patched_add_patched_create_batch_patched_send_event_patched_send_batchr"   r   r   r   r!   )   s(   
r!   c                 C   sD   t |}|r| s| |i |S t||ddd|_| |i |S )Nr   fully_qualified_namespaceT)r   get_fromenabledr	   _dd_fully_qualified_namespace)wrappedinstanceargskwargspinr   r   r   r+   F   s
   
r+   c                 C   sN   t |}|r| rtjjs| |i |S | |i |}|j|_|j|_|S r   	r   r5   r6   r   r   r   eventhub_name_dd_eventhub_namer7   r8   r9   r:   r;   r<   batchr   r   r   r1   P   s   
r1   c                    s\   t |}|r| rtjjs| |i |I d H S | |i |I d H }|j|_|j|_|S r   r=   r@   r   r   r   r,   ]   s   
r,   c           	   	   C   s   t |}|r| rtjjrt|dd rt|dd s"| |i |S |j}|j}t	j
 dt	j dt	j }td|||}t|||t	j||d | |i |W  d    S 1 sYw   Y  d S )Nr?   r7   .z&azure.eventhubs.patched_producer_batch
event_data)r   r5   r6   r   r   r   r   r?   r7   azure_eventhubsxCLOUDSERVICECREATEr   r   	r8   r9   r:   r;   r<   resource_namer4   operation_namectxr   r   r   r0   j   s*   



$r0   c           	   	   C      t |}|r| s| |i |S |j}|j}tj dtj dtj }t	d|||}t
|||tj||d | |i |W  d    S 1 sIw   Y  d S NrB   z%azure.eventhubs.patched_producer_sendrC   r   r5   r6   r>   r7   rD   rE   rF   SENDr   r   rH   r   r   r   r2         
$r2   c           	   	         t |}|r| s| |i |I d H S |j}|j}tj dtj dtj }t	d|||}t
|||tj||d | |i |I d H W  d    S 1 sPw   Y  d S rM   rN   rH   r   r   r   r-         
$r-   c           	   	   C   rL   NrB   z+azure.eventhubs.patched_producer_send_batchevent_data_batchrN   rH   r   r   r   r3      rP   r3   c           	   	      rQ   rS   rN   rH   r   r   r   r.      rR   r.   c                  C   r   r   )r   r    _unpatchr"   r   r   r   unpatch   r%   rV   c                 C   s|   t | ddsd S d| _t| jd t| jd t| jd t| jd t| jd t| jd | jd	kr<t| jd
 d S d S )Nr&   F__init__create_batch
send_event
send_batch_buffered_send_event_buffered_send_batchr   add)r   r&   _ur)   r'   r/   r"   r   r   r   rU      s   
rU   )/azure.eventhubeventhubr   azure.eventhub.aioaior    wraptr   r*   ddtracer   ddtrace._trace.pinr   $ddtrace.contrib.internal.trace_utilsr   r^   ddtrace.extr   rD   ddtrace.internal.schemar   !ddtrace.internal.settings._configr   ddtrace.internal.utilsr	   ddtrace.internal.utils.formatsr
   utilsr   r   _adddictstrr   r   r$   r!   r+   r1   r,   r0   r2   r-   r3   r.   rV   rU   r   r   r   r   <module>   sF    

