
    ghv#                        S r SSKrSSKJrJr  SSKJrJrJrJ	r	J
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  \
\	\
\   \4      r " S	 S
\5      r " S S\5      rS rS\\\4   S\\\4   4S jrS\\\4   SS4S jrS\\\4   SS4S jrS\\\4   SS4S jrS\\\4   S\4S jrS\\\4   S\4S jr  " S S5      r! " S S\5      r"g)ae  
This integration ingests tracing data from native extensions written in Rust.

Using it requires additional setup on the Rust side to accept a
`RustTracingLayer` Python object and register it with the `tracing-subscriber`
using an adapter from the `pyo3-python-tracing-subscriber` crate. For example:
```rust
#[pyfunction]
pub fn initialize_tracing(py_impl: Bound<'_, PyAny>) {
    tracing_subscriber::registry()
        .with(pyo3_python_tracing_subscriber::PythonCallbackLayerBridge::new(py_impl))
        .init();
}
```

Usage in Python would then look like:
```
sentry_sdk.init(
    dsn=sentry_dsn,
    integrations=[
        RustTracingIntegration(
            "demo_rust_extension",
            demo_rust_extension.initialize_tracing,
            event_type_mapping=event_type_mapping,
        )
    ],
)
```

Each native extension requires its own integration.
    N)Enumauto)AnyCallableDictTupleOptional)Integration)should_send_default_pii)Span)SENSITIVE_DATA_SUBSTITUTEc                   (    \ rS rSrSrSrSrSrSrSr	g)	RustTracingLevel.   TRACEDEBUGINFOWARNERROR N)
__name__
__module____qualname____firstlineno__TraceDebugInfoWarnError__static_attributes__r       g/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/rust_tracing.pyr   r   .   s    EEDDEr!   r   c                   L    \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       rSr	g)EventTypeMapping6   r   N)
r   r   r   r   r   IgnoreExc
BreadcrumbEventr    r   r!   r"   r$   r$   6   s    VF
&CJFEr!   r$   c                     [        U 5      n U [         R                  [         R                  4;   a  gU [         R                  :X  a  gU [         R                  :X  a  gU [         R
                  :X  a  gg)Ndebuginfowarningerror)r   r   r   r   r   r   )levels    r"   tracing_level_to_sentry_levelr0   =   se    U#E!'')9)?)?@@	"''	'	"''	'	"((	( r!   eventreturnc                    U R                  S0 5      n0 n0 nS H  nXA;   d  M
  X   X4'   M     [        U5      S:  a  X2S'   0 nUR                  S/ 5       H  nU R                  U5      XT'   M     [        U5      S:  a  XRS'   U$ )Nmetadata)module_pathfileliner   rust_tracing_locationfieldsrust_tracing_fields)getlen)r1   r4   contextslocationfieldr9   s         r"   extract_contextsr@   M   s    yyR(HHH0&oHO 1 8}q,4()Fh+		%( ,
6{Q*0&'Or!   c                     U R                  S0 5      nUR                  S5      n[        UR                  S5      5      nU R                  S5      n[        U 5      nUUUUS.n[        R                  " U5        g )Nr4   targetr/   message)loggerr/   rC   r=   )r;   r0   r@   
sentry_sdkcapture_event)r1   r4   rD   r/   rC   r=   sentry_events          r"   process_eventrH   a   sp    yyR(H\\(#F)(,,w*?@Eii	"G&H 	L \*r!   c                     [        U 5        g N)rH   )r1   s    r"   process_exceptionrK   s   s
    %r!   c                     [        U R                  S0 5      R                  S5      5      nU R                  S5      n[        R                  " XS9  g )Nr4   r/   rC   )r/   rC   )r0   r;   rE   add_breadcrumb)r1   r/   rC   s      r"   process_breadcrumbrN   w   s>    )%))J*C*G*G*PQEii	"GE;r!   r4   c                     [        U R                  S5      5      [         R                  [         R                  [         R                  4;   $ Nr/   )r   r;   r   r   r   )r4   s    r"   default_span_filterrQ   ~   s=    HLL127  r!   c                 n   [        U R                  S5      5      nU[         R                  :X  a  [        R                  $ U[         R
                  [         R                  4;   a  [        R                  $ U[         R                  [         R                  4;   a  [        R                  $ [        R                  $ rP   )r   r;   r   r$   r'   r   r   r(   r   r   r&   )r4   r/   s     r"   default_event_type_mappingrS      s    X\\'23E &&&###	#((*:*?*?@	@***	#))+;+A+AB	B&&&&&&r!   c            
           \ rS rSr\\S4S\S\\\\	4   /\
4   S\\\\	4   /\4   S\\   4S jjrS\4S	 jrS
\S\SS4S jrS\S\S\4S jrS\S\SS4S jrS\S\S\SS4S jrSrg)RustTracingLayer   Noriginevent_type_mappingspan_filterinclude_tracing_fieldsc                 4    Xl         X l        X0l        X@l        g rJ   )rW   rX   rY   rZ   )selfrW   rX   rY   rZ   s        r"   __init__RustTracingLayer.__init__   s     "4&&<#r!   r2   c                 H    U R                   c
  [        5       $ U R                   $ )a  
By default, the values of tracing fields are not included in case they
contain PII. A user may override that by passing `True` for the
`include_tracing_fields` keyword argument of this integration or by
setting `send_default_pii` to `True` in their Sentry client options.
)rZ   r   )r\   s    r"   _include_tracing_fields(RustTracingLayer._include_tracing_fields   s-     **2 $%	
 ,,	
r!   r1   _span_statec                 `   [         R                  " U5      nUR                  S0 5      nU R                  U5      nU[        R
                  :X  a  g U[        R                  :X  a  [        U5        g U[        R                  :X  a  [        U5        g U[        R                  :X  a  [        U5        g g )Nr4   )jsonloadsr;   rX   r$   r&   r'   rK   r(   rN   r)   rH   )r\   r1   rb   deserialized_eventr4   
event_types         r"   on_eventRustTracingLayer.on_event   s    !ZZ.%))*b9,,X6
)000+///01+66612+111,- 2r!   attrsspan_idc                    [         R                  " U5      nUR                  S0 5      nU R                  U5      (       d  g UR                  S5      nUR                  S5      nUR                  S5      nUb  UnOUb  Ub  U SU 3nOUb  UnOSnSUU R                  S.n[
        R                  " 5       n	U	R                  n
U
(       a  U
R                  " S
0 UD6nOU	R                  " S
0 UD6nUR                  S	/ 5      nU HP  nU R                  5       (       a"  UR                  XR                  U5      5        M:  UR                  U[        5        MR     Xl        X4$ )Nr4   r5   namerC   z::z	<unknown>function)oprm   rW   r9   r   )rd   re   r;   rY   rW   rE   get_current_scopespanstart_child
start_spanr`   set_datar   )r\   rj   rk   r4   r5   rm   rC   sentry_span_namekwargsscopeparent_sentry_spansentry_spanr9   r?   s                 r"   on_new_spanRustTracingLayer.on_new_span   sR   

5!99Z,))ll=1||F#))I&&$)9"-b7#* $kk
 ,,."ZZ,88B6BK**4V4Kh+E++--$$UIIe,<=$$U,EF	  !
"00r!   
span_statec                 h    Uc  g Uu  p4UR                  5         U[        R                  " 5       l        g rJ   )finishrE   rp   rq   )r\   rk   r|   rx   ry   s        r"   on_closeRustTracingLayer.on_close   s1    *4'.@
$$&+r!   valuesc                     Uc  g Uu  pE[         R                  " U5      nUR                  5        HC  u  pxU R                  5       (       a  UR	                  Xx5        M-  UR	                  U[
        5        ME     g rJ   )rd   re   itemsr`   rt   r   )	r\   rk   r   r|   _parent_sentry_spanry   deserialized_valueskeyvalues	            r"   	on_recordRustTracingLayer.on_record   sf    +5("jj0-335JC++--$$S0$$S*CD	 6r!   )rX   rZ   rW   rY   )r   r   r   r   rS   rQ   strr   r   r   r$   boolr	   r]   r`   
TraceStaterh   rz   r   r   r    r   r!   r"   rU   rU      s     '8K15== %#s(^..
= tCH~.45= !)=
 
.c .
 .t .)1 )1s )1z )1VA A A A
E 
Ec 
Ez 
Ed 
Er!   rU   c                       \ rS rSrSr\\S4S\S\\	/S4   S\\
\\4   /\4   S\\
\\4   /\4   S\\   4
S	 jjr\SS
 j5       rSrg)RustTracingIntegration   a  
Ingests tracing data from a Rust native extension's `tracing` instrumentation.

If a project uses more than one Rust native extension, each one will need
its own instance of `RustTracingIntegration` with an initializer function
specific to that extension.

Since all of the setup for this integration requires instance-specific state
which is not available in `setup_once()`, setup instead happens in `__init__()`.
N
identifierinitializerrX   rY   rZ   c                 `    Xl         SU 3n[        XcXE5      U l        U" U R                  5        g )Nzauto.function.rust_tracing.)r   rU   tracing_layer)r\   r   r   rX   rY   rZ   rW   s          r"   r]   RustTracingIntegration.__init__  s7     %.zl;-
 	D&&'r!   c                      g rJ   r   r   r!   r"   
setup_once!RustTracingIntegration.setup_once  s    r!   )r   r   )r2   N)r   r   r   r   __doc__rS   rQ   r   r   rU   r   r   r$   r   r	   r]   staticmethodr   r    r   r!   r"   r   r      s    	" '8K15(( /0$67( %#s(^..
	( tCH~.45( !)($  r!   r   )#r   rd   enumr   r   typingr   r   r   r   r	   rE   sentry_sdk.integrationsr
   sentry_sdk.scoper   sentry_sdk.tracingr   
SentrySpansentry_sdk.utilsr   r   r   r$   r0   r   r@   rH   rK   rN   r   rQ   rS   rU   r   r   r!   r"   <module>r      s$  @   7 7  / 4 1 6eHZ0*<=>
t t  DcN tCH~ (+c3h +D +$T#s(^  <d38n < <$sCx. T 	'c3h 	'<L 	'gE gET [  r!   