
    fi                     ,   d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ 	 d dlmZ n# e$ r  ed          w xY wd d	lmZ erd d
lmZmZmZ d dlmZmZmZ g dZd Zd Z G d dej                  Z  G d de	          Z!dS )    N)
SPANSTATUSSPANDATAOP)DidNotEnableIntegration)should_send_default_pii)Span)capture_internal_exceptions)
monitoringzPymongo not installed)TYPE_CHECKING)AnyDictUnion)CommandFailedEventCommandStartedEventCommandSucceededEvent)insertorderedfindlimitsingleBatch	aggregatecreateIndexesindexesdeletefindAndModifyrenameCollectiontodropc                 "   | D ]}|t           v }|r|dk    od| v}|r|dk    }|r| |         D ]}|D ]}d||<   9|dv }|r| |         D ]}d| |         |<   V|dk    }	|	r(| |         D ]}
d|
v r|
d         ng D ]}d|
d         |<   d| |<   | S )Nupdater   	documentsz%s)filterqueryr!   pipelinez$match)SAFE_COMMAND_ATTRIBUTES)commandkeyis_safe_fieldupdate_db_commandis_documentdocdoc_keyis_dict_fielditem_keyis_pipeline_fieldr%   	match_keys               o/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/sentry_sdk/integrations/pymongo.py
_strip_piir3   -   sE    $ $66 	8ONw0N 	  [( 	s| ( (" ( (G#'CLL( << 	#CL . .)-X&&  :- 	#CL 9 97?87K7K(!3!3QS 9 9I48HX&y119 N    c                     i }d|t           j        <   | j        }|||t           j        <   | j        d         }|||t           j        <   | j        d         }|||t           j        <   |S )Nmongodbr      )r   	DB_SYSTEMdatabase_nameDB_NAMEconnection_idSERVER_ADDRESSSERVER_PORT)eventdatadb_nameserver_addressserver_ports        r2   _get_db_datarC   X   st    D(D	!G!(X(+N!(6X$%%a(K%0X!"Kr4   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )CommandTracerc                     i | _         d S N)_ongoing_operations)selfs    r2   __init__zCommandTracer.__init__n   s    #%   r4   c                     |j         S rG   )
request_id)rI   r>   s     r2   _operation_keyzCommandTracer._operation_keyr   s    r4   c                 F   t          j                                        t                    d S t	                      5  t          t          j        |j                            }|	                    dd            |	                    dd            |	                    dd            d|j
        t          j        dt          j        |j        t          j        |                    |j                  i}	 |j        d         |d<   t%          |j        d                   |d	<   n# t&          $ r Y nw xY wd
i i}|j        |d
         d<   |j        |d
         d<   |                    t/          |                     	 |	                    d          d         }t%          |          |d
         d<   n# t0          $ r Y nw xY wt3                      st5          |          }t7          j        |t$                    }t          j        t<          j        |t          j                   }|!                                D ]1\  }}	|"                    ||	           |#                    ||	           2|!                                D ]\  }
}	|#                    |
|	           t	                      5  t          j$        |dt<          j        |           d d d            n# 1 swxY w Y   |%                                | j&        | '                    |          <   d d d            d S # 1 swxY w Y   d S )Nz$dbz$clusterTimez
$signaturezdb.namer6   r   znet.peer.namer7   znet.peer.portoperation_ids	operationrequestlsididsession)default)opnameoriginr$   )messagecategorytyper?   )(
sentry_sdk
get_clientget_integrationPyMongoIntegrationr
   dictcopydeepcopyr'   popr9   r   r8   DB_OPERATIONcommand_nameDB_MONGODB_COLLECTIONgetr;   str	TypeErroroperation_idrL   r!   rC   KeyErrorr   r3   jsondumps
start_spanr   DBrX   itemsset_tagset_dataadd_breadcrumb	__enter__rH   rM   )rI   r>   r'   tagsr?   rR   r$   spantagvaluer(   s              r2   startedzCommandTracer.startedv   s    ""223EFFNF(** 9	T 9	T4=7788GKKt$$$KK---KKd+++ 5."I%u'9.E<N0O0O	D(-(;A(>_%(+E,?,B(C(C_%%    $R(D161CD!+./4/?D!),KKU++,,,{{6**4036t99_%i00    +,, .$W--Jw444E(5)0  D #jjll * *
U S%(((c5))))"jjll * *
Uc5)))),..  )!G"%d                 
 DH>>CSCSD$T%8%8%?%?@s9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	T 9	Ts   B3L0-DL
D+(L*D++A	L53F)(L)
F63L5F66C*L #KLK	LK	2LLLc                 J   t          j                                        t                    d S 	 | j                            |                     |                    }|                    t          j	                   |
                    d d d            d S # t          $ r Y d S w xY wrG   )r\   r]   r^   r_   rH   rc   rM   
set_statusr   INTERNAL_ERROR__exit__rk   rI   r>   rv   s      r2   failedzCommandTracer.failed   s     ""223EFFNF	+//0C0CE0J0JKKDOOJ5666MM$d+++++ 	 	 	FF	   A#B 
B"!B"c                 J   t          j                                        t                    d S 	 | j                            |                     |                    }|                    t          j	                   |
                    d d d            d S # t          $ r Y d S w xY wrG   )r\   r]   r^   r_   rH   rc   rM   r{   r   OKr}   rk   r~   s      r2   	succeededzCommandTracer.succeeded   s     ""223EFFNF	+//0C0CE0J0JKKDOOJM***MM$d+++++ 	 	 	DD	r   N)__name__
__module____qualname__rJ   rM   ry   r   r    r4   r2   rE   rE   m   sc        & & &     >T >T >T@
 
 

 
 
 
 
r4   rE   c                   2    e Zd ZdZde Zed             ZdS )r_   pymongozauto.db.c                  F    t          j        t                                 d S rG   )r   registerrE   r   r4   r2   
setup_oncezPyMongoIntegration.setup_once   s     	MOO,,,,,r4   N)r   r   r   
identifierrX   staticmethodr   r   r4   r2   r_   r_      s?        J$
$$F- - \- - -r4   r_   )"ra   rl   r\   sentry_sdk.constsr   r   r   sentry_sdk.integrationsr   r   sentry_sdk.scoper   sentry_sdk.tracingr	   sentry_sdk.utilsr
   r   r   ImportErrortypingr   r   r   r   pymongo.monitoringr   r   r   r&   r3   rC   CommandListenerrE   r_   r   r4   r2   <module>r      s         6 6 6 6 6 6 6 6 6 6 = = = = = = = = 4 4 4 4 4 4 # # # # # # 8 8 8 8 8 80""""""" 0 0 0
,.
/
//0 !           ''''''''''            "( ( (V  *_ _ _ _ _J. _ _ _D- - - - - - - - - -s	   9 A
