
    \j                     2   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r5d 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 y)    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y)BeamIntegrationbeamNc            	          ddl m} m} t        d       t        d       g dD ],  }t	        | t
        j                  |      t        | |             . |j                  	 	 	 	 	 	 	 	 	 	 dfd}||_        y )Nr   )DoFnParDorootzbundle_processor.create)processstart_bundlefinish_bundlesetupc                 ~   t        | dd      sD ]  }t        ||      st        j                  |      }t        ||      }t        |t        j                  |            }t        |t
        d      rbt        |t
        d      rtt        |||       t        ||t        |              d| _         	| |g|i | y )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_inits
           F/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardoz5BeamIntegration.setup_once.<locals>.sentry_init_pardo6   s     4!5u=!1 NI"2y1 #/#6#6y#AL $+2y#9L#*2|/B/B9/M#NL"<EB7$iL  L,?I|/LMN" +/'T2///    )
r)   r   r*   r   r+   r   r,   r   returnr   )	apache_beam.transforms.corer   r   r   r'   r%   r$   _wrap_inspect_call__init__)r   r   r-   r4   r1   r2   s       @@r3   
setup_oncezBeamIntegration.setup_once%   s    ;f/0P) 	I##I."43	 >>	0	0$	0-2	0>C	0	02 +r5   r6   N)__name__
__module____qualname__
identifierstaticmethodr:    r5   r3   r   r   "   s    J)+ )+r5   r   c                 P    t        |       sy dfd}t        |t        d       |S )Nc                    t         j                        }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   rD   ImportError apache_beam.typehints.decoratorsrE   )r)   r.   r/   rD   rE   r-   s        r3   _inspectz$_wrap_inspect_call.<locals>._inspectV   s     $**954&"46L"43LD)_\%BCD,5	0N-l;; 	0G!,//	0s    A. .BBT)r)   r   r6   r   )r"   r'   r&   )clsr-   rH   s    ` r3   r8   r8   R   s(    3	"0. Hi&Or5   c                 R     t               d fd       }t        |t        d       |S )z<
    Wrap task call with a try catch to get exceptions.
    c                      	  | i |}t        t        j                        s|S t        |      S # t         $ r t                Y <w xY w)N)	Exceptionraise_exception
isinstancetypesGeneratorType_wrap_generator_call)r+   r,   genfuncs      r3   _innerz_wrap_task_call.<locals>._innerv   sP    	''C #u223J#C((  		s   2 AAT)r+   r   r,   r   r6   r   )r   r'   r&   )rS   rT   s   ` r3   r(   r(   q   s.    
 4[) ) FIt$Mr5   c                     t        j                         }t        | |j                  ddd      \  }}t        j                  ||       y)z(
    Send Beam exception to Sentry.
    r   F)typehandled)client_options	mechanism)hintN)
sentry_sdk
get_clientr   optionscapture_event)exc_infoclienteventrZ   s       r3   _capture_exceptionrb      sD    
 ""$F&~~!e4KE4
 U.r5   c                      t        j                         } t               5  t        |        ddd       t	        |   y# 1 sw Y   xY w)z
    Raise an exception.
    N)sysr_   r   rb   r	   )r_   s    r3   rM   rM      s:     ||~H	$	& %8$%X% %s	   <Ac              #   p   K   	 	 t        |        # t        $ r Y yt        $ r t                Y  w xY ww)z4
    Wrap the generator to handle any failures.
    N)nextStopIterationrL   rM   )rR   s    r3   rQ   rQ      s?      	s)O   	 		s$   6 6	363636)rI   r   r-   r   r6   r   )rS   r   r6   r   )r_   r   r6   Nr;   )rR   Iterator[T]r6   rh   )!rd   rO   	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   rM   rQ   rA   r5   r3   <module>ro      s    
    / 9  !)A8CH-.A 	-+k -+`>( O,/ -/
r5   