o
    S۷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dZd)ddZeed*d d!Zd+d"d#Zd,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dZdS )BeamIntegrationbeamreturnNc                     s~   ddl m} m} td td g d  D ]}t| t|t| | q|j						
								d fdd}||_d S )Nr   )DoFnParDorootzbundle_processor.create)processstart_bundlefinish_bundlesetupselfr   fnr
   argskwargsr   c                    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!   )r   r   r   r    	func_namewrapped_funcprocess_funcinspect_funcfunction_patchesold_init R/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardo6   s   


z5BeamIntegration.setup_once.<locals>.sentry_init_pardo)
r   r   r   r
   r   r
   r    r
   r   r
   )	apache_beam.transforms.corer   r   r   r(   r&   r%   _wrap_inspect_call__init__)r   r   r*   r3   r1   r.   r2   
setup_once%   s.   
zBeamIntegration.setup_oncer   N)__name__
__module____qualname__
identifierstaticmethodr7   r1   r1   r1   r2   r   "   s    r   clsr
   r*   r   c                    s,   t |  sd S d fdd}t|td |S )Nr   r
   r   c                    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)   r4   r?   ImportError apache_beam.typehints.decoratorsr@   )r   r+   r,   r?   r@   r*   r1   r2   _inspectV   s   



z$_wrap_inspect_call.<locals>._inspectT)r   r
   r   r
   )r#   r(   r'   )r>   r*   rD   r1   rC   r2   r5   R   s
   
r5   funcc                    s&   t  d	 fdd}t|td |S )
z<
    Wrap task call with a try catch to get exceptions.
    r   r
   r    r   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rE   r1   r2   _innerv   s   
z_wrap_task_call.<locals>._innerTN)r   r
   r    r
   r   r
   )r   r(   r'   )rE   rN   r1   rM   r2   r)   q   s   
r)   exc_infor   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)rO   clienteventrT   r1   r1   r2   _capture_exception   s   
r[   c                  C   sB   t  } t  t|  W d   n1 sw   Y  t|   dS )z
    Raise an exception.
    N)sysrO   r   r[   r   )rO   r1   r1   r2   rG      s
   
rG   rL   Iterator[T]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StopIterationrF   rG   )rL   r1   r1   r2   rK      s   
rK   )r>   r
   r*   r
   r   r
   )rE   r   r   r   )rO   r   r   Nr8   )rL   r]   r   r]   )!r\   rI   	functoolsr   rU   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   r5   r)   r[   rG   rK   r1   r1   r1   r2   <module>   s4    
0


