
    lh.7                        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m	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZ 	 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"m#Z# 	 d dl$m%Z&m'Z( d dl)m*Z* e*r*d dl)m+Z+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl!m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8  ed        G d de	      Z9d Z: G d de      Z; G d de;      Z<d Z=d  Z>d! Z?d" Z@y# e$ r	  e
d
      w xY w# e$ r	  e
d      w xY w# e$ r dZ&dZ(Y w xY w)#    Nisawaitable)OP)_check_minimum_versionIntegrationDidNotEnable)ignore_logger)should_send_default_pii)TransactionSource)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionloggerpackage_version_get_installed_modules)cached_propertyz;strawberry-graphql integration requires Python 3.8 or newer)Schema)SchemaExtension)should_skip_tracing)async_base_viewsync_base_viewz#strawberry-graphql is not installed)SentryTracingExtensionSentryTracingExtensionSync)TYPE_CHECKING)AnyCallable	GeneratorListOptional)GraphQLErrorGraphQLResolveInfo)GraphQLHTTPResponse)ExecutionContext)EventEventProcessorzstrawberry.executionc                   2    e Zd ZdZde ZddZed        Zy)StrawberryIntegration
strawberryzauto.graphql.Nc                 N    |dvrt        dj                  |            || _        y )N)NFTz6Invalid value for async_execution: "{}" (must be bool))
ValueErrorformatasync_execution)selfr,   s     t/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/strawberry.py__init__zStrawberryIntegration.__init__A   s3    "55HOO# 
  /    c                  d    t        d      } t        t        | d       t                t	                y )Nzstrawberry-graphql)r   r   r'   _patch_schema_init_patch_views)versions    r.   
setup_oncez StrawberryIntegration.setup_onceK   s(     ""674g?STr0   N)__name__
__module____qualname__
identifieroriginr/   staticmethodr5    r0   r.   r'   r'   =   s,    JZL)F/  r0   r'   c                  v    t         j                  t        j                        fd       } | t         _        y )Nc                    t        j                         j                  t              }| | g|i |S |j	                  d      xs g }|j
                  |j
                  }n*t        |      }t        j                  d|rdnd|rdnd       |D cg c]  }|t        t        fvr| }}|j                  |rt        nt               ||d<    | g|i |S c c}w )N
extensionszfAssuming strawberry is running %s. If not, initialize it as StrawberryIntegration(async_execution=%s).asyncsyncFalseTrue)
sentry_sdk
get_clientget_integrationr'   getr,   _guess_if_using_asyncr   infoStrawberrySentryAsyncExtensionStrawberrySentrySyncExtensionappendSentryAsyncExtensionSentrySyncExtension)r-   argskwargsintegrationr@   should_use_async_extension	extensionold_schema_inits          r.   _sentry_patched_schema_initz7_patch_schema_init.<locals>._sentry_patched_schema_initY   s     !++-==>ST"49$9&99ZZ-3
&&2)4)D)D& *?z)J&KKx5656 (
24QRS 

 
 	$> DW	
  *|t5d5f55
s   C)r   r/   	functoolswraps)rV   rU   s    @r.   r2   r2   U   s1    ooO___%#6 &#6J 2FOr0   c                   R    e Zd ZdddZed        Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)rN   Nexecution_contextc                    |r|| _         y y r6   rZ   )r-   r[   s     r.   r/   zSentryAsyncExtension.__init__   s     %6D" r0   c                     | j                  | j                  j                        }| j                  j                  r&dj	                  | j                  j                  |      S |S )Nz{}:{})
hash_queryr[   queryoperation_namer+   )r-   
query_hashs     r.   _resource_namez#SentryAsyncExtension._resource_name   sP     __T%;%;%A%AB
!!00>>$"8"8"G"GTTr0   c                 f    t        j                  |j                  d            j                         S )Nzutf-8)hashlibmd5encode	hexdigest)r-   r_   s     r.   r^   zSentryAsyncExtension.hash_query   s#    {{5<<01;;==r0   c              #     K   | j                   j                  | _        d}t        j                  }| j                   j
                  d| j                   _        | j                   j
                  j                         j                  d      rd}t        j                  }nE| j                   j
                  j                         j                  d      rd}t        j                  }|}| j                  r|dj                  | j                        z  }t        j                  d| j                  |d       t        j                         }t        | j                         }|j                  |       t        j                          }|r(|j#                  ||t$        j&                  	      | _        n+t        j*                  ||t$        j&                  	      | _        | j(                  j-                  d
|       | j(                  j-                  d| j                         | j(                  j-                  d| j                   j
                         | j(                  j-                  d| j.                         d  | j(                  j0                  }|rM| j                   j                  r7| j                   j                  |_        t4        j6                  |_        ||_        | j(                  j=                          y w)Nr_    mutationsubscriptionz {}zgraphql.operation)r`   operation_type)categorydataopnamer;   zgraphql.operation.typezgraphql.operation.namezgraphql.documentzgraphql.resource_name)r[   r`   _operation_namer   GRAPHQL_QUERYr_   strip
startswithGRAPHQL_MUTATIONGRAPHQL_SUBSCRIPTIONr+   rE   add_breadcrumbget_isolation_scope_make_request_event_processoradd_event_processorget_current_spanstart_childr'   r;   graphql_span
start_spanset_datarb   containing_transactionrq   r   	COMPONENTsourcerp   finish)r-   rl   rp   descriptionscopeevent_processorspantransactions           r.   on_operationz!SentryAsyncExtension.on_operation   sY    #55DD !!''/+-D""(!!''--/:::F'N$$B##))//1<<^L+N((B$5<<(<(<==K!!("&"6"6"0	
 ..078N8NO!!/2**, $ 0 0 ,33 !1 !D !+ 5 5 ,33!D 	""#;^L""#;T=Q=QR""#5t7M7M7S7ST""#:D<O<OP''>>411@@#55DDK!2!<!<KKN  "s   K/K1c              #      K   | j                   j                  t        j                  dt        j
                        | _        d  | j                  j                          y w)N
validationro   )r~   r}   r   GRAPHQL_VALIDATEr'   r;   validation_spanr   r-   s    r.   on_validatez SentryAsyncExtension.on_validate   sP     #00<<""(//  =  
 	##%   AA!c              #      K   | j                   j                  t        j                  dt        j
                        | _        d  | j                  j                          y w)Nparsingro   )r~   r}   r   GRAPHQL_PARSEr'   r;   parsing_spanr   r   s    r.   on_parsezSentryAsyncExtension.on_parse   sP      --99(// : 
 	  "r   c                     t        ||      S r6   )strawberry_should_skip_tracing)r-   _nextrJ   s      r.   r   z(SentryAsyncExtension.should_skip_tracing   s    -eT::r0   c                 V   K    |||g|i |}t        |      r
| d {   }|S 7 wr6   r   )r-   r   rootrJ   rP   rQ   results          r.   _resolvezSentryAsyncExtension._resolve   s5     tT3D3F3v!\F "s   )')c                   K   | j                  ||      r  | j                  |||g|i | d {   S dj                  |j                  |j                        }| j
                  j                  t        j                  dj                  |      t        j                        5 }|j                  d|j                         |j                  d|j                  j                         |j                  d|       |j                  ddj                  t        t        |j                   j#                                             | j                  |||g|i | d {   cd d d        S 7 97 # 1 sw Y   y xY ww	Nz{}.{}zresolving {}ro   zgraphql.field_namezgraphql.parent_typezgraphql.field_pathzgraphql.path.)r   r   r+   parent_type
field_namer~   r}   r   GRAPHQL_RESOLVEr'   r;   r   rq   joinmapstrpathas_listr-   r   r   rJ   rP   rQ   
field_pathr   s           r.   resolvezSentryAsyncExtension.resolve   sC    ##E40&udDJ4J6JJJ^^D$4$4dooF
**!!&&z2(// + 
 
	K MM.@MM/1A1A1F1FGMM.
;MM.#((3sDII<M<M<O3P*QR&udDJ4J6JJ
	K 
	K	 K K
	K 
	Ks;   .E:E)A3E:$B7E.E,E.E:,E..E73E:)r7   r8   r9   r/   r   rb   r^   r   r   r   r   r   r   r=   r0   r.   rN   rN      sE     7  ><#|
&
#;Kr0   rN   c                       e Zd Zd Zy)rO   c                    | j                  ||      r |||g|i |S dj                  |j                  |j                        }| j                  j                  t        j                  dj                  |      t        j                        5 }|j                  d|j                         |j                  d|j                  j                         |j                  d|       |j                  ddj                  t        t        |j                  j!                                             |||g|i |cd d d        S # 1 sw Y   y xY wr   )r   r+   r   r   r~   r}   r   r   r'   r;   r   rq   r   r   r   r   r   r   s           r.   r   zSentrySyncExtension.resolve  s   ##E40t5d5f55^^D$4$4dooF
**!!&&z2(// + 
 
	6 MM.@MM/1A1A1F1FGMM.
;MM.#((3sDII<M<M<O3P*QRt5d5f5
	6 
	6 
	6s   B(EE
N)r7   r8   r9   r   r=   r0   r.   rO   rO     s    6r0   rO   c                     t         j                  j                  t        j                  j                  fd} fd}t        t              d        | t         j                  _        |t        j                  _        y )Nc                 .     | ||        | ||       y r6   r=   )r-   errorsresponse_data_sentry_patched_handle_errorsold_async_view_handle_errorss      r.   (_sentry_patched_async_view_handle_errorsz>_patch_views.<locals>._sentry_patched_async_view_handle_errors+  s    $T6=A%dFMBr0   c                 .     | ||        | ||       y r6   r=   )r-   r   r   r   old_sync_view_handle_errorss      r.   '_sentry_patched_sync_view_handle_errorsz=_patch_views.<locals>._sentry_patched_sync_view_handle_errors0  s    #D&-@%dFMBr0   c           	      b   |sy t        j                         }t        |      }|j                  |       t	               5  |D ]W  }t        |t        j                         j                  t        j                  dd      \  }}t        j                  ||       Y 	 d d d        y # 1 sw Y   y xY w)NF)typehandled)client_options	mechanism)hint)rE   ry   _make_response_event_processorr{   r   r   rF   optionsr'   r:   capture_event)r-   r   r   r   r   erroreventr   s           r.   r   z3_patch_views.<locals>._sentry_patched_handle_errors5  s     ..08G!!/2(* 
	; 	;2#-#8#8#:#B#B 5 @ @#(t ((T:	;
	; 
	; 
	;s   AB%%B.)r   AsyncBaseHTTPView_handle_errorsr   SyncBaseHTTPViewr   r'   )r   r   r   r   r   s     @@@r.   r3   r3   &  ss    #2#D#D#S#S "0"A"A"P"PC
C
   56; 7;, 	1 %%4 	0 ##2r0   c                       fd}|S )Nc                 x   t               5  t               rr| j                  di       }d|d<   |j                  d      sQdj                  i}j
                  rj
                  |d<   j                  rj                  |d<   ||d<   n	 | d   d= d d d        | S # t        t        f$ r Y w xY w# 1 sw Y   | S xY w)Nrequestgraphql
api_targetrn   r_   	variablesoperationName)	r   r
   
setdefaultrH   r_   r   r`   KeyError	TypeError)r   r   request_datarn   r[   s       r.   innerz,_make_request_event_processor.<locals>.innerV  s    (* 	&($//	2>-6\*#''/#%6%<%<=D(22,=,G,G[)(770A0P0P_-+/L(i(0!	(  !), #	( s*   A=B/
BB,)B/+B,,B//B9r=   )r[   r   s   ` r.   rz   rz   S  s    0 Lr0   c                       fd}|S )Nc                     t               5  t               r| j                  di       }di|d<   d d d        | S # 1 sw Y   | S xY w)Ncontextsrn   response)r   r
   r   )r   r   r   r   s      r.   r   z-_make_response_event_processor.<locals>.innert  sN    (* 	?&( ++J;(.'>$	?
 	?
 s	   $:Ar=   )r   r   s   ` r.   r   r   q  s     Lr0   c                 h    t         | v ryt        | v ryt        h dt        t	                     z        S )NTF>   fastapilitestarstarlite	starlette)rK   rL   boolsetr   )r@   s    r.   rI   rI     s6    %3	&*	483?U?W;XX r0   )ArW   rd   inspectr   rE   sentry_sdk.constsr   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr	   sentry_sdk.scoper
   sentry_sdk.tracingr   sentry_sdk.utilsr   r   r   r   r   r   r   ImportErrorr(   r   strawberry.extensionsr   #strawberry.extensions.tracing.utilsr   r   strawberry.httpr   r   strawberry.extensions.tracingr   rK   r   rL   typingr   r   r   r   r   r   r   r    r!   r"   strawberry.typesr#   sentry_sdk._typesr$   r%   r'   r2   rN   rO   r3   rz   r   rI   r=   r0   r.   <module>r      s         U U 9 4 0 V)>!5 @) !??8317 $ %K 0*2ZLK? LK^6. 6**Z<	U  V
 T
UUV  >
<
==>  )%)"$(!)s*   C C, (C= C),C:=	D	D	