o
    h>                     @   s  d dl Z d dl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
mZmZmZ d dlmZ er^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eedd Zdd Zdd Z dS )    N)wraps)Integration)ignore_logger)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionreraise)TYPE_CHECKING)Any)Iterator)TypeVar)Callable)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/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardo7   s   


z5BeamIntegration.setup_once.<locals>.sentry_init_pardo)	apache_beam.transforms.corer   r   r   r#   r!   r    _wrap_inspect_call__init__)r   r   r)   r2   r0   r-   r1   
setup_once%   s   
zBeamIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr6   r0   r0   r0   r1   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$   r3   r<   ImportError apache_beam.typehints.decoratorsr=   )r%   r*   r+   r<   r=   r)   r0   r1   _inspectX   s   



z$_wrap_inspect_call.<locals>._inspectT)r   r#   r"   )clsr)   rA   r0   r@   r1   r4   R   s
   
r4   c                    s$   t   fdd}t|td |S )z<
    Wrap task call with a try catch to get exceptions.
    c                     sD   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funcr0   r1   _innerz   s   
z_wrap_task_call.<locals>._innerT)r   r#   r"   )rK   rL   r0   rJ   r1   r$   t   s   r$   c                 C   s4   t  }t| |jdddd\}}t j||d dS )z(
    Send Beam exception to Sentry.
    r   F)typehandled)client_options	mechanism)hintN)
sentry_sdk
get_clientr   optionscapture_event)exc_infoclienteventrQ   r0   r0   r1   _capture_exception   s   
rY   c                  C   sB   t  } t  t|  W d   n1 sw   Y  t|   dS )z
    Raise an exception.
    N)sysrV   r   rY   r   )rV   r0   r0   r1   rD      s
   
rD   c                 c   s@    	 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StopIterationrC   rD   )rI   r0   r0   r1   rH      s   
rH   )!rZ   rF   	functoolsr   rR   sentry_sdk.integrationsr   sentry_sdk.integrations.loggingr   sentry_sdk.utilsr   r   r   r   typingr	   r
   r   r   r   sentry_sdk._typesr   r   r   r   r!   r"   r   r4   r$   rY   rD   rH   r0   r0   r0   r1   <module>   s4    0"
