U 췀gv@sddlZddlmZddlmZddlZddlmZddlm Z ddl m Z m Z ddl mZmZddlmZerdd lmZmZmZdd lmZzdd lmZmZWnek red YnXz ddlZWnek red YnXdZGdddeZddZddZdS)N)deepcopy)wraps) DidNotEnable)should_send_default_pii)SOURCE_FOR_STYLETRANSACTION_SOURCE_ROUTE)transaction_from_functionlogger) TYPE_CHECKING)AnyCallableDict)Event)StarletteIntegrationStarletteRequestExtractorzStarlette is not installedzFastAPI is not installedzgeneric FastAPI requestc@seZdZdZeddZdS)FastApiIntegrationfastapicCs tdSN)patch_get_request_handlerrrM/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/fastapi.py setup_once(szFastApiIntegration.setup_onceN)__name__ __module__ __qualname__ identifier staticmethodrrrrrr%srcCsd}|dkr*|jd}|rZt|p&d}n0|dkrZ|jd}|rZt|dd}|dk rZ|}|sht}t}nt|}|j||dt d||dS)Nendpointurlroutepath)sourcez;[FastAPI] Set transaction name and source on scope: %s / %s) scopegetrgetattr_DEFAULT_TRANSACTION_NAMErrZset_transaction_namer debug)r#transaction_stylerequestnamerr r!r"rrr _set_transaction_name_and_source.s*   r+cs tjjfdd}|tj_dS)Ncs^|d}|rD|jdk rDt|jsD|jtfdd}||_||fdd}|S)N dependantcsBt}|jdk r|jt}|jdk r8|j||Sr) sentry_sdkget_current_scopeZ transactionZupdate_active_threadget_isolation_scopeZprofileZupdate_active_thread_id)argskwargsZ current_scope sentry_scope)old_callrr _sentry_callXs    zTpatch_get_request_handler.._sentry_get_request_handler.._sentry_callcstt}|dkr&||IdHS|d}tt|j|t}t|}| IdHfdd}tj |_ | |||||IdHS)Nrcsfdd}|S)NcsN|di}r>dkr*tr*d|d<dkr>d|d<t||d<|S)Nr)cookiesdata)r$rr)eventhintZ request_infoinforrevent_processorzs    zpatch_get_request_handler.._sentry_get_request_handler.._sentry_app.._make_request_event_processor..event_processorr)req integrationr;r9rr_make_request_event_processorxs zzpatch_get_request_handler.._sentry_get_request_handler.._sentry_app.._make_request_event_processor) r-Z get_clientZget_integrationrr+r.r(r/rZextract_request_infor_nameZadd_event_processor)r0r1r=r)r2Z extractorr>)old_appr9r _sentry_appis$ zSpatch_get_request_handler.._sentry_get_request_handler.._sentry_app)r$callasyncioiscoroutinefunctionr)r0r1r,r4rAZold_get_request_handler)r@r3r_sentry_get_request_handlerNs     (z>patch_get_request_handler.._sentry_get_request_handler)rZroutingZget_request_handler)rFrrErrJs Er) rCcopyr functoolsrr-Zsentry_sdk.integrationsrZsentry_sdk.scoperZsentry_sdk.tracingrrZsentry_sdk.utilsrr typingr r r r Zsentry_sdk._typesrZ!sentry_sdk.integrations.starletterrr ImportErrorr&rr+rrrrrs.