U 췀g@sddlmZddlZddlmZmZmZmZmZddl Z ddl m Z m Z ddl mZmZddlmZddlmZmZddlmZmZmZzddlZdd lmZWnek red YnXeejZedk red kred Gd ddeZedZ dddddZ!ededZ"ej#ddddddddddZ$dddddd d!d"Z%d#d#dd$d%Z&dddd&d'Z'd(d)d*d+d,d-Z(dS).) annotationsN)AnyTypeVarCallable AwaitableIterator)OPSPANDATA) Integration DidNotEnable)Span)add_query_sourcerecord_sql_queries)ensure_integration_enabled parse_versioncapture_internal_exceptions) BaseCursorzasyncpg not installed.)rrzasyncpg >= 0.23.0 requiredc@sDeZdZdZdeZdZddddddZedd d d Zd S) AsyncPGIntegrationasyncpgzauto.db.F) record_paramsboolcCs |t_dS)N)r_record_params)selfrrM/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/asyncpg.py__init__#szAsyncPGIntegration.__init__None)returncCshttjjtj_ttjjtj_ttjjddtj_ttjjtj_ttjj tj_ t tj j tj _ dS)NT executemany) _wrap_executer Connectionexecute_wrap_connection_methodZ_executeZ _executemany_wrap_cursor_creationcursorprepare_wrap_connect_addrZ connect_utilsZ _connect_addrrrrr setup_once&s zAsyncPGIntegration.setup_onceN) __name__ __module__ __qualname__ identifieroriginrr staticmethodr)rrrrrs  rTzCallable[..., Awaitable[T]])frcsddddfdd }|S)Nrr0argskwargsrc sttdkr"||IdHSt|dkr>||IdHS|d}td|dddtjd}||IdH}W5QRXtt|W5QRX|S)NF)r&query params_list paramstyler span_origin) sentry_sdk get_clientget_integrationrlenrr.rr )r3r4r7spanresr1rr_inner=s$ z_wrap_execute.._innerrr1rBrrArr!<sr! SubCursor)boundFrzSubCursor | Nonestrztuple[Any, ...] | NonerzIterator[Span])r&r7r8r rc cs^tt}|dk r |js d}|r(dnd}t||||||dk tjd }|VW5QRXdS)NZpyformat)r&r7r8r9r Zrecord_cursor_reprr:)r;r<r=rrrr.)r&r7r8r Z integrationZ param_styler?rrr_record^s rG)r1r rcsddddfdd }|S)Nrr0r2c sttdkr"||IdHS|d}t|dkr>|dnd}td||d$}t||d||IdH}W5QRX|S)Nr6r5rr)r;r<r=rr>rG _set_db_datar3r4r7r8r?r@r r1rrrB{sz'_wrap_connection_method.._innerr)r1r rBrrJrr$xs r$zCallable[..., T]cs$ttddddfdd }|S)Nrr0r2c sd|d}t|dkr|dnd}td||dd*}t||d||}|d|W5QRX|S)Nr6r5Frrz db.cursor)r>rGrHset_datarIrArrrBs z%_wrap_cursor_creation.._inner)rrrCrrArr%sr%csddddfdd }|S)Nrr0r2c sttdkr"||IdHS|dj}|dj}tjtjdtj d}| t j d| d}|rz(| t j|d| t j|dWntk rYnX| t j|| t j|ttjdd|jd W5QRX||IdH}W5QRX|S) Nparamsconnect)opnamer. postgresqladdrrr6r7)messagecategorydata)r;r<r=ruserdatabaseZ start_spanrZDBr.rKr DB_SYSTEMgetSERVER_ADDRESS SERVER_PORT IndexErrorDB_NAMEDB_USERrZadd_breadcrumb_data)r3r4rUrVr?rQr@rArrrBs8   z"_wrap_connect_addr.._innerrrCrrArr(sr(r rr)r?connrcCs|tjd|j}|rVz(|tj|d|tj|dWntk rTYnX|jj}|rp|tj ||jj }|r|tj |dS)NrPrr6) rKr rWZ_addrrYrZr[_paramsrVr\rUr])r?r_rQrVrUrrrrHsrH)) __future__r contextlibtypingrrrrrr;Zsentry_sdk.constsrr Zsentry_sdk.integrationsr r Zsentry_sdk.tracingr Zsentry_sdk.tracing_utilsr rZsentry_sdk.utilsrrrrZasyncpg.cursorr ImportError __version__Zasyncpg_versionrr0r!rDcontextmanagerrGr$r%r(rHrrrrs8    #