o
    h9                     @   s0  d dl mZ d dl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mZ d dlmZ d dlmZ d d	lmZ ertd 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Zededef dZdZdZdZ G dd deZ!dd Z"dd Z#dd Z$d d! Z%d"d# Z&dS )$    )absolute_importN)wraps)Hub)reraise)capture_internal_exceptionsevent_from_exception)Integration)ignore_logger)TYPE_CHECKING)Any)Iterator)TypeVar)Optional)Callable)Client)ExcInfoTF.)boundz_wrapped_{}_z_inspect_{}_sentry_used_c                   @   s   e Zd ZdZedd ZdS )BeamIntegrationbeamc                     sh   ddl m} m} td td g d  D ]}t| t|t| | q|j fdd}||_d S )Nr   )DoFnParDorootzbundle_processor.create)processstart_bundlefinish_bundlesetupc                    s   t | dds@ D ]4}t||sqt|}t ||}t |t|}t |tds<t |tds<t||| t||t| qd| _| |g|R i | d S )N_sentry_is_patchedFT)	getattrhasattrWRAPPED_FUNCformatINSPECT_FUNC	USED_FUNCsetattr_wrap_task_callr   )selffnargskwargs	func_namewrapped_funcprocess_funcinspect_funcfunction_patchesold_init _/var/www/html/aiguide_backend/venv/lib/python3.10/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardo6   s   


z5BeamIntegration.setup_once.<locals>.sentry_init_pardo)	apache_beam.transforms.corer   r   r	   r&   r$   r#   _wrap_inspect_call__init__)r   r   r,   r5   r3   r0   r4   
setup_once$   s   
zBeamIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr9   r3   r3   r3   r4   r   !   s    r   c                    s*   t |  sd S  fdd}t|td |S )Nc                    s   t  }t| |rt| |}nt|  }t|  t| t| || zddlm} ||W S  tyA   ddl	m
} || Y S w )zG
        Inspect function overrides the way Beam gets argspec.
        r   )get_function_args_defaults)getfullargspec)r"   r#   r!   r    r&   r'   r6   r?   ImportError apache_beam.typehints.decoratorsr@   )r(   r-   r.   r?   r@   r,   r3   r4   _inspectW   s   



z$_wrap_inspect_call.<locals>._inspectT)r!   r&   r%   )clsr,   rD   r3   rC   r4   r7   Q   s
   
r7   c                    s.   t jj t fdd}t|td |S )z~
    Wrap task call with a try catch to get exceptions.
    Pass the client on to raise_exception so it can get rebinded.
    c                     sH   z	| i |}W n t y   t  Y nw t|tjs|S t| S )N)	Exceptionraise_exception
isinstancetypesGeneratorType_wrap_generator_call)r*   r+   genclientfuncr3   r4   _inner{   s   
z_wrap_task_call.<locals>._innerT)r   currentrN   r   r&   r%   )rO   rP   r3   rM   r4   r'   s   s
   r'   c                 C   sT   | t}|du rdS |j}|du rdS t| |jdddd\}}|j||d dS )z(
    Send Beam exception to Sentry.
    Nr   F)typehandled)client_options	mechanism)hint)get_integrationr   rN   r   optionscapture_event)exc_infohubintegrationrN   eventrV   r3   r3   r4   _capture_exception   s   

r^   c                 C   s^   t j}|jdu r||  t }t  t|| W d   n1 s$w   Y  t|  dS )zI
    Raise an exception. If the client is not in the hub, rebind it.
    N)	r   rQ   rN   bind_clientsysrZ   r   r^   r   )rN   r[   rZ   r3   r3   r4   rG      s   

rG   c                 c   sB    	 zt | V  W n ty   Y dS  ty   t| Y nw q)z4
    Wrap the generator to handle any failures.
    TN)nextStopIterationrF   rG   )rL   rN   r3   r3   r4   rK      s   rK   )'
__future__r   r`   rI   sentry_sdk._functoolsr   sentry_sdk.hubr   sentry_sdk._compatr   sentry_sdk.utilsr   r   sentry_sdk.integrationsr   sentry_sdk.integrations.loggingr	   sentry_sdk._typesr
   typingr   r   r   r   r   sentry_sdk.clientr   r   r   r   r"   r$   r%   r   r7   r'   r^   rG   rK   r3   r3   r3   r4   <module>   s:    0"