o
    0 i>                     @   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_{}Z_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)processZstart_bundleZ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_funcZinspect_funcZfunction_patchesZold_init h/home/app/PaddleOCR-VL-test/.venv_paddleocr/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&   r,   r*   r)   r+   
setup_once%   s   
zBeamIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr0   r*   r*   r*   r+   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!   r-   r6   ImportErrorZ apache_beam.typehints.decoratorsr7   )r"   r'   r(   r6   r7   r&   r*   r+   _inspectX   s   



z$_wrap_inspect_call.<locals>._inspectT)r   r    r   )clsr&   r:   r*   r9   r+   r.   R   s
   
r.   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funcr*   r+   _innerz   s   
z_wrap_task_call.<locals>._innerT)r   r    r   )rD   rE   r*   rC   r+   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)typeZhandled)Zclient_optionsZ	mechanism)hintN)
sentry_sdkZ
get_clientr   optionsZcapture_event)exc_infoclienteventrG   r*   r*   r+   _capture_exception   s   
rM   c                  C   sB   t  } t  t|  W d   n1 sw   Y  t|   dS )z
    Raise an exception.
    N)sysrJ   r   rM   r   )rJ   r*   r*   r+   r=      s
   
r=   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StopIterationr<   r=   )rB   r*   r*   r+   rA      s   
rA   )!rN   r?   	functoolsr   rH   Zsentry_sdk.integrationsr   Zsentry_sdk.integrations.loggingr   Zsentry_sdk.utilsr   r   r   r   typingr	   r
   r   r   r   Zsentry_sdk._typesr   r   r   r   r   r   r   r.   r!   rM   r=   rA   r*   r*   r*   r+   <module>   s4    0"
