o
    BDi                     @   s   d dl Z d dl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Zd dlmZ W n ey7   edw d dlmZmZ erTd dlmZ d d	lmZ d d
lmZ dd Zdd Zdd ZG dd deZdS )    N)OP)IntegrationDidNotEnable)event_from_exceptionloggerreraise)Taskzasyncio not available)castTYPE_CHECKING)Any)	Coroutine)ExcInfoc                 C   s   t | dd pt | dd pdS )N__qualname____name__zcoroutine without __name__)getattrcoro r   X/var/www/Datamplify/venv/lib/python3.10/site-packages/sentry_sdk/integrations/asyncio.pyget_name   s
   
r   c                     sP   d  zt  } |    fdd}| | W d S  ty'   td Y d S w )Nc                    s    fdd}d }r| | fi |}|d u r*t | fd| i|}|jr*|jd= ztd|t  d W |S  tyD   Y |S w )Nc               
      s   d } t  C t jtjt tjd z I d H } W n ty*   t	t
   Y nw W d    n1 s5w   Y  W d    | S W d    | S 1 sMw   Y  | S )N)opnameorigin)
sentry_sdkisolation_scope
start_spanr   FUNCTIONr   AsyncioIntegrationr   	Exceptionr   _capture_exception)resultr   r   r   _task_with_sentry_span_creation*   s,   


zTpatch_asyncio.<locals>._sentry_task_factory.<locals>._task_with_sentry_span_creationloopzasyncio.Task[Any]z (Sentry-wrapped))r   _source_tracebackr	   set_namer   AttributeError)r"   r   kwargsr!   taskorig_task_factoryr   r   _sentry_task_factory'   s*   
z+patch_asyncio.<locals>._sentry_task_factoryzThere is no running asyncio loop so there is nothing Sentry can patch. Please make sure you call sentry_sdk.init() within a running asyncio loop for the AsyncioIntegration to work. See https://docs.sentry.io/platforms/python/integrations/asyncio/)asyncioget_running_loopget_task_factoryset_task_factoryRuntimeErrorr   warning)r"   r+   r   r)   r   patch_asyncio    s   3
r2   c                  C   sN   t  } t }|t}|d ur%t| |jdddd\}}tj||d | S )Nr,   F)typehandled)client_options	mechanism)hint)	sysexc_infor   
get_clientget_integrationr   r   optionscapture_event)r9   clientintegrationeventr7   r   r   r   r   f   s   

r   c                   @   s&   e Zd ZdZde Zedd ZdS )r   r,   zauto.function.c                   C   s
   t   d S )N)r2   r   r   r   r   
setup_once|   s   
zAsyncioIntegration.setup_onceN)r   
__module__r   
identifierr   staticmethodrA   r   r   r   r   r   x   s
    
r   )r8   r   sentry_sdk.constsr   sentry_sdk.integrationsr   r   sentry_sdk.utilsr   r   r   r,   asyncio.tasksr   ImportErrortypingr	   r
   r   collections.abcr   sentry_sdk._typesr   r   r2   r   r   r   r   r   r   <module>   s(    	F