ó
    Ð]j¿  ã                  óD  • S SK Jr  S SKrS SKJs  Jr  S SKrS SK	r	S SK
Jr  S SKJr  S SKJr  S SKJr  S SKJrJrJrJr  S SKrSS	KJrJr  \(       a  SS
KJr              SS jr                SS jr\ " S S\5      5       r\" S5      r SS jr!SS jr"g)é    )ÚannotationsN)Údeque)ÚAbstractContextManager)Ú	dataclass)Úpartial)ÚTYPE_CHECKINGÚAnyÚCallableÚTypeVaré   )ÚBaseTransformerÚLogfireArgs)ÚLogfirec           	     óf  ^	^
^• S[         R                  " 5       R                   3m/ m
[        XTX#T
U5      n [        R
                  n[        X5      of(       Gd@  SS[        R                  " 5       ;   d  [        R                  " [        5      (       a  [        R                  " [        5      OSS[        R                  " 5       ;   d  [        R                  " U 5      (       a  [        R                  " U 5      OSS[        R                  " 5       ;   d  [        R                  " [        5      (       a  [        R                  " [        5      OS[        R                  " U5      [        R                  " U5      S.-  n[        [        R                  " U5      5      eS=pV[        XSS	S
9m	SU	U
U4S jjnU$ )aù  Compile a modified AST of the module's source code in the module's namespace.

Returns a function which accepts module globals and executes the compiled code.

The modified AST wraps the body of every function definition in `with context_factories[index]():`.
`context_factories` is added to the module's namespace as `logfire_<uuid>`.
`index` is a different constant number for each function definition.
`context_factories[index]` is one of these:
    - `partial(logfire_instance._fast_span, name, attributes)` where the name and attributes
        are constructed from `filename`, `module_name`, attributes of `logfire_instance`,
        and the qualified name and line number of the current function.
    - `MeasureTime`, a class that measures the time elapsed. If it exceeds `min_duration`,
        then `context_factories[index]` is replaced with the `partial` above.
If `min_duration` is greater than 0, then `context_factories[index]` is initially `MeasureTime`.
Otherwise, it's initially the `partial` above.
Úlogfire_zQassert %(py6)s
{%(py6)s = %(py0)s(%(py1)s, %(py4)s
{%(py4)s = %(py2)s.Module
})
}Ú
isinstanceÚtreeÚast)Úpy0Úpy1Úpy2Úpy4Úpy6NÚexecT)Údont_inheritc                ó(   >• TU T'   [        TX 5        g ©N)r   )ÚglobsÚcodeÚcontext_factoriesÚlogfire_names    €€€Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/logfire/_internal/auto_trace/rewrite_ast.pyÚexecuteÚcompile_source.<locals>.execute-   s   ø€ Ø/ˆˆlÑÜˆT�5Õ ó    )r   zdict[str, Any])ÚuuidÚuuid4ÚhexÚrewrite_astr   ÚModuler   Ú@py_builtinsÚlocalsÚ
@pytest_arÚ_should_repr_global_nameÚ	_safereprÚAssertionErrorÚ_format_explanationÚcompile)r   ÚfilenameÚmodule_nameÚlogfire_instanceÚmin_durationÚ@py_assert3Ú@py_assert5Ú@py_format7r#   r   r    r!   s            @@@r"   Úcompile_sourcer:      sý   ú€ ð& œdŸjšj›l×.Ñ.Ð/Ð0€LØIKÐÜ�t |°[ÐTeÐgsÓt€DÜŸJ™JÐ'Œ:�dÓ'Ð'Ö'×'×'×'×'×'Ñ'Œ:×'×'×'Ñ'Œ:×'×'×'×'×'Ö'�d×'×'×'Ñ'�d×'×'×'×'×'Ö'œC×'×'×'Ñ'œC×'×'Õ'˜J×'×'Ó'Ð'×'×'×'×'×'Ò'ä�4 6¸Ñ=€D÷!ñ !ð €Nr%   c           	     ó€   • [        UR                  UR                  5      n[        XrXXEU5      nUR	                  U 5      $ r   )r   Ú_tagsÚ_sample_rateÚAutoTraceTransformerÚvisit)	r   r3   r!   r4   r5   r    r6   Úlogfire_argsÚtransformers	            r"   r)   r)   4   sF   € ô Ð/×5Ñ5Ð7G×7TÑ7TÓU€LÜ&Ø HÐ;KÐ`ló€Kð ×Ñ˜TÓ"Ð"r%   c                  ó„   ^ • \ rS rSr% SrS\S'   S\S'   S\S'   SS	 jrSU 4S
 jjrSU 4S jjrSU 4S jjr	SS jr
SrU =r$ )r>   éD   zUTrace all encountered functions except those explicitly marked with `@no_auto_trace`.r   r5   ú/list[Callable[[], AbstractContextManager[Any]]]r    Úintr6   c                ó:   • [        S UR                   5       5      $ )zUReturn true if the node has a `@no_auto_trace` or `@logfire.no_auto_trace` decorator.c              3  óÚ  #   • U  Há  n[        U[        R                  5      =(       a    UR                  [        R
                  :H  =(       d—    [        U[        R                  5      =(       av    UR                  [        R
                  :H  =(       aR    [        UR                  [        R                  5      =(       a'    UR                  R                  [        R
                  :H  v •  Mã     g 7fr   )
r   r   ÚNameÚidÚno_auto_traceÚ__name__Ú	AttributeÚattrÚvalueÚlogfire)Ú.0Únodes     r"   Ú	<genexpr>Ú;AutoTraceTransformer.check_no_auto_trace.<locals>.<genexpr>N   s¢   é € ð 
ò ,�ô ˜4¤§¡Ó*÷ 6Ø—G‘Gœ}×5Ñ5Ñ5÷ô ˜t¤S§]¡]Ó3÷ :ØŸ	™	¤]×%;Ñ%;Ñ;÷:ä" 4§:¡:¬s¯x©xÓ8÷:ð Ÿ
™
Ÿ™¬×)9Ñ)9Ñ9ôò ,ùs   ‚C)C+)ÚanyÚdecorator_list)ÚselfrQ   s     r"   Úcheck_no_auto_traceÚ(AutoTraceTransformer.check_no_auto_traceL   s$   € äñ 
ð ×+Ò+ó
ó 
ð 	
r%   c                óR   >• U R                  U5      (       a  U$ [        TU ]	  U5      $ r   )rW   ÚsuperÚvisit_ClassDef©rV   rQ   Ú	__class__s     €r"   r[   Ú#AutoTraceTransformer.visit_ClassDef\   s)   ø€ Ø×#Ñ# D×)Ñ)ØˆKä‰wÑ% dÓ+Ð+r%   c                óR   >• U R                  U5      (       a  U$ [        TU ]	  U5      $ r   )rW   rZ   Úvisit_FunctionDefr\   s     €r"   r`   Ú&AutoTraceTransformer.visit_FunctionDefb   s)   ø€ Ø×#Ñ# D×)Ñ)ØˆKä‰wÑ(¨Ó.Ð.r%   c                óF   >• [        U5      (       a  U$ [        TU ]	  X5      $ r   )Ú	has_yieldrZ   Úrewrite_function)rV   rQ   Úqualnamer]   s      €r"   rd   Ú%AutoTraceTransformer.rewrite_functionh   s!   ø€ Ü�T�?‰?ØˆKä‰wÑ'¨Ó7Ð7r%   c                óê  ^ ^^^^• [        T R                  5      m[        T R                  R                  /T R                  X!R                  5      Q76 mT R                  S:”  ae  T R                  R                  nUR                  R                  mT R                  m " UUU UU4S jS5      nT R                  R                  U5        OT R                  R                  T5        [        R                  " [        R                  " [        R                  " T R                   [        R"                  " 5       S9[        R$                  " [        R&                  " TS9S9[        R"                  " 5       S9/ / S9$ )Nr   c                  ó:   >• \ rS rSrSrU4S jrU UUUU4S jrSrg)ÚBAutoTraceTransformer.logfire_method_call_node.<locals>.MeasureTimeé~   Ústartc                ó   >• T" 5       U l         g r   )rk   )Ú_selfÚtimers    €r"   Ú	__enter__ÚLAutoTraceTransformer.logfire_method_call_node.<locals>.MeasureTime.__enter__�   s   ø€ Ù"'£'�E•Kr%   c                óV   >• T" 5       U R                   -
  T:¼  a  TTR                  T'   g g r   )rk   r    )rm   Ú_Úindexr6   rV   Úspan_factoryrn   s     €€€€€r"   Ú__exit__ÚKAutoTraceTransformer.logfire_method_call_node.<locals>.MeasureTime.__exit__„   s+   ø€ Ù“w §¡Ñ,°Ó<Ø8D˜×.Ñ.¨uÒ5ð =r%   © N)rK   Ú
__module__Ú__qualname__Ú__firstlineno__Ú	__slots__ro   ru   Ú__static_attributes__)rs   r6   rV   rt   rn   s   €€€€€r"   ÚMeasureTimeri   ~   s   ø† Ø#�	õ*÷Eô Er%   r}   )rI   Úctx)rN   )rN   Úslicer~   )ÚfuncÚargsÚkeywords)Úlenr    r   r5   Ú
_fast_spanÚlogfire_method_arg_valuesÚlinenor6   Ú_configÚadvancedÚns_timestamp_generatorÚappendr   ÚCallÚ	SubscriptrH   Úlogfire_method_nameÚLoadÚIndexÚConstant)	rV   rQ   re   Úconfigr}   rs   r6   rt   rn   s	   `    @@@@r"   Úlogfire_method_call_nodeÚ-AutoTraceTransformer.logfire_method_call_noden   s  ü€ ä�D×*Ñ*Ó+ˆÜØ×!Ñ!×,Ñ,ð
à×+Ñ+¨H·k±kÓBò
ˆð ×Ñ˜qÓ Ø×*Ñ*×2Ñ2ˆFð —O‘O×:Ñ:ˆEØ×,Ñ,ˆL÷E÷ Eð Eð ×"Ñ"×)Ñ)¨+Õ6à×"Ñ"×)Ñ)¨,Ô7ô �xŠxÜ—’Ü—h’h $×":Ñ":ÄÇÂÃ
ÑKÜ—i’i¤c§l¢l¸Ñ&?Ñ@Ü—H’H“Jñð
 Øñ
ð 	
r%   rw   )rQ   z5ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDefÚreturnÚbool)rQ   zast.ClassDef)rQ   ú&ast.FunctionDef | ast.AsyncFunctionDef)rQ   r–   re   Ústrr”   úast.AST)rQ   r–   re   r—   r”   zast.Call)rK   rx   ry   rz   Ú__doc__Ú__annotations__rW   r[   r`   rd   r’   r|   Ú__classcell__)r]   s   @r"   r>   r>   D   s6   ø‡ á_àÓØFÓFØÓô
÷ ,÷/÷8÷*
ò *
r%   r>   ÚTc                ó   • U $ )aš  Decorator to prevent a function/class from being traced by `logfire.install_auto_tracing`.

This is useful for small functions that are called very frequently and would generate too much noise.

The decorator is detected at import time.
Only `@no_auto_trace` or `@logfire.no_auto_trace` are supported.
Renaming/aliasing either the function or module won't work.
Neither will calling this indirectly via another function.

Any decorated function, or any function defined anywhere inside a decorated function/class,
will be completely ignored by `logfire.install_auto_tracing`.

This decorator simply returns the argument unchanged, so there is zero runtime overhead.
rw   )Úxs    r"   rJ   rJ   ž   s	   € ð €Hr%   c                óœ  • [        U /5      nU(       a¹  UR                  5       n [        R                  " U 5       H…  n[	        U[        R
                  [        R                  45      (       a    g[	        U[        R                  [        R                  [        R                  45      (       a  Mt  UR                  U5        M‡     U(       a  M¸  g g )NT)r   Úpopleftr   Úiter_child_nodesr   ÚYieldÚ	YieldFromÚFunctionDefÚAsyncFunctionDefÚLambdarŠ   )rQ   ÚqueueÚchilds      r"   rc   rc   °   s‚   € Ü�4�&‹M€EÞ
Ø�}‰}‹ˆÜ×)Ò)¨$Ö/ˆEÜ˜%¤#§)¡)¬S¯]©]Ð!;×<Ñ<ÙÜ˜e¤c§o¡o´s×7KÑ7KÌSÏZÉZÐ%X×YÓYØ—‘˜UÖ#ñ	 0÷ Š%r%   )r   r˜   r3   r—   r4   r—   r5   r   r6   rE   r”   z Callable[[dict[str, Any]], None])r   r˜   r3   r—   r!   r—   r4   r—   r5   r   r    rD   r6   rE   r”   r˜   )rž   rœ   r”   rœ   )rQ   r˜   )#Ú
__future__r   Úbuiltinsr+   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter-   r   r&   Úcollectionsr   Ú
contextlibr   Údataclassesr   Ú	functoolsr   Útypingr   r	   r
   r   rO   Ú	ast_utilsr   r   Úmainr   r:   r)   r>   rœ   rJ   rc   rw   r%   r"   Ú<module>rµ      sì   ðÝ "ç  „ ƒ
Û Ý Ý -Ý !Ý ß 8Ó 8ã ç 4æÝðØ
ðØ ðØ/2ðØFMðØ]`ðà%ôðB#Ø
ð#àð#ð ð#ð ð	#ð
 ð#ð Gð#ð ð#ð ô#ð  ôS
˜?ó S
ó ðS
ñl ˆCƒL€ôõ$$r%   