
    tni                     X   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                   ZdZdZdZ G 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                   *    e Zd ZdZedd            ZdS )BeamIntegrationbeamreturnNc            	         ddl m} m} t          d           t          d           g dD ]9}t	          | t
                              |          t          | |                     :|j        	 	 	 	 	 	 	 	 	 	 dfd}||_        d S )Nr   )DoFnParDorootzbundle_processor.create)processstart_bundlefinish_bundlesetupselfr   fnr   argskwargsr   c                    t          | dd          sʉD ]}t          ||          st                              |          }t          ||          }t          |t                              |                    }t          |t
          d          sEt          |t
          d          s/t          |||           t          ||t          |                     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_inits
           Y/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardoz5BeamIntegration.setup_once.<locals>.sentry_init_pardo6   s    4!5u== /!1 N NI"2y11 ! #/#6#6y#A#AL $+2y#9#9L#*2|/B/B9/M/M#N#NL"<EBB N7$iL L N  L,???I|/L/LMMM*.'HT2/////////    )
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.   r5   r2   r3   s       @@r4   
setup_oncezBeamIntegration.setup_once%   s    ;;;;;;;;f/000PPP) 	 	I##I.."433    >	0	0$	0-2	0>C	0	0 	0 	0 	0 	0 	0 	02 +r6   r   N)__name__
__module____qualname__
identifierstaticmethodr:    r6   r4   r   r   "   s7        J)+ )+ )+ \)+ )+ )+r6   r   clsr   r.   r   c                 d    t          |           sd S dfd}t          |t          d           |S )Nr    r   r   c                 ^   t                                         }t          | |          rt          | |          }n?t          |           }t	          | t          |                     t	          | ||           	 ddlm}  ||          S # t          $ r ddl	m
}  ||          cY S w xY w)zG
        Inspect function overrides the way Beam gets argspec.
        r   )get_function_args_defaults)getfullargspec)r(   r)   r'   r&   r,   r-   r7   rE   ImportError apache_beam.typehints.decoratorsrF   )r    r/   r0   rE   rF   r.   s        r4   _inspectz$_wrap_inspect_call.<locals>._inspectV   s     $**9554&& 	6"466LL"433LD)_\%B%BCCCD,555	0NNNNNN--l;;; 	0 	0 	0GGGGGG!>,/////	0s   =B B,+B,T)r    r   r   r   )r'   r,   r+   )rB   r.   rI   s    ` r4   r8   r8   R   sQ    3	"" t0 0 0 0 0 0. Hi&&&Or6   funcc                 j     t                     d fd            }t          |t          d           |S )z<
    Wrap task call with a try catch to get exceptions.
    r"   r   r#   r   c                      	  | i |}n# t           $ r t                       Y nw xY wt          |t          j                  s|S t          |          S )N)	Exceptionraise_exception
isinstancetypesGeneratorType_wrap_generator_call)r"   r#   genrJ   s      r4   _innerz_wrap_task_call.<locals>._innerv   su    	$'''CC 	 	 		 #u233 	J#C(((s    ''T)r"   r   r#   r   r   r   )r   r,   r+   )rJ   rT   s   ` r4   r-   r-   q   sL    
 4[[) ) ) ) ) [) FIt$$$Mr6   exc_infor   c                     t          j                    }t          | |j        ddd          \  }}t          j        ||           dS )z(
    Send Beam exception to Sentry.
    r   F)typehandled)client_options	mechanism)hintN)
sentry_sdk
get_clientr   optionscapture_event)rU   clienteventr[   s       r4   _capture_exceptionrb      s[    
 "$$F&~!e44  KE4
 U......r6   c                      t          j                    } t                      5  t          |            ddd           n# 1 swxY w Y   t	          |   dS )z
    Raise an exception.
    N)sysrU   r   rb   r	   )rU   s    r4   rN   rN      s     |~~H	$	&	& % %8$$$% % % % % % % % % % % % % % %Xs   >AArS   Iterator[T]c              #      K   	 	 t          |           V  n*# t          $ r Y dS t          $ r t                       Y nw xY w>)z4
    Wrap the generator to handle any failures.
    TN)nextStopIterationrM   rN   )rS   s    r4   rR   rR      sl      	s))OOOO 	 	 	EE 	 	 		s    
>>>)rB   r   r.   r   r   r   )rJ   r   r   r   )rU   r   r   Nr;   )rS   re   r   re   )!rd   rP   	functoolsr   r\   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   r8   r-   rb   rN   rR   rA   r6   r4   <module>ro      s   



            / / / / / / 9 9 9 9 9 9            !           	/))))))A8CH-...A 	-+ -+ -+ -+ -+k -+ -+ -+`   >   ( O,,/ / / -,/   
 
 
 
 
 
r6   