Ë
    S>{ið  ã                   ó  — d Z ddlZddl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 dd	lmZ 	 dd
lmZ ddlmZmZ ddlmZ ddlmZ erddlmZ dddœZ G d„ de«      Zd„ Zd„ Z d„ Z!d„ Z"y# e$ r	  ed«      ‚w xY w)zÈ
IMPORTANT: The contents of this file are part of a proof of concept and as such
are experimental and not suitable for production use. They may be changed or
removed at any time without prior notice.
é    N)Úimport_module)ÚDidNotEnableÚIntegration)ÚSentrySpanProcessor)ÚSentryPropagator)Ú_get_installed_modules)Úlogger)ÚTYPE_CHECKING)Útrace)Ú_load_distroÚ_load_instrumentors)Úset_global_textmap)ÚTracerProviderzopentelemetry not installed)ÚDictzfastapi.FastAPIzflask.Flask)ÚfastapiÚflaskc                   ó    — e Zd ZdZed„ «       Zy)ÚOpenTelemetryIntegrationÚopentelemetryc                  ót  — t        j                  d«       t        «       } 	 t        «       }|j	                  «        t        |«       	 t        | «       t        «        t        j                  d«       y # t        $ r t        j                  d«       Y ŒLw xY w# t        $ r t        j                  d«       Y Œdw xY w)NzT[OTel] Initializing highly experimental OpenTelemetry support. Use at your own risk.z.[OTel] Failed to auto-initialize OpenTelemetryz‰[OTel] Failed to post-patch instrumented classes. You might have to make sure sentry_sdk.init() is called before importing anything else.z4[OTel] Finished setting up OpenTelemetry integration)r	   ÚwarningÚ_record_unpatched_classesr   Ú	configurer   Ú	ExceptionÚ	exceptionÚ_patch_remaining_classesÚ_setup_sentry_tracingÚdebug)Úoriginal_classesÚdistros     úo/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sentry_sdk/integrations/opentelemetry/integration.pyÚ
setup_oncez#OpenTelemetryIntegration.setup_once+   sª   € ô 	�‰ð$ô	
ô
 5Ó6Ðð	OÜ!“^ˆFØ×ÑÔÜ Ô'ð	Ü$Ð%5Ô6ô 	Ôä�‰ÐKÕLøô ò 	OÜ×ÑÐMÖNð	Oûô
 ò 	Ü×Ñðjöð	ús#   ¡%A2 ÁB Á2BÂBÂB7Â6B7N)Ú__name__Ú
__module__Ú__qualname__Ú
identifierÚstaticmethodr"   © ó    r!   r   r   (   s   „ Ø €JàñMó ñMr)   r   c                  óØ   — t        «       } i }t        j                  «       D ]  \  }}|| v sŒ	 t        |«      }|||<   Œ |S # t        t
        f$ r t        j                  d|«       Y ŒGw xY w)z½
    Keep references to classes that are about to be instrumented.

    Used to search for unpatched classes after the instrumentation has run so
    that they can be patched manually.
    z[OTel] Failed to import %s)r   ÚCLASSES_TO_INSTRUMENTÚitemsÚ_import_by_pathÚAttributeErrorÚImportErrorr	   r   )Úinstalled_packagesr   ÚpackageÚ	orig_pathÚoriginal_clss        r!   r   r   I   s…   € ô 0Ó1ÐàÐä3×9Ñ9Ó;ò 5Ñˆ�ØÐ(Ò(ðÜ.¨yÓ9�ð
 )5Ð˜WÒ%ð5ð Ðøô #¤KÐ0ò Ü—‘Ð9¸9ÔEÙðús   ­AÁ%A)Á(A)c           	      ó²  — i }t        | j                  «       «      D ];  }t        |   }	 t        |«      }|j                  j                  d«      s| |= Œ7|||<   Œ= |syt        j                  j                  «       j                  «       D ]�  \  }}|j                  d«      s|t        j                  v rŒ*| j                  «       D ]a  \  }}t        |«      j                  «       j                  «       D ]2  \  }}	|	|k(  sŒt        j                  d||«       t!        ||||   «       Œ4 Œc ŒŸ y# t        t
        f$ r t        j                  d|«       | |= Y �Œ9w xY w)a  
    Best-effort attempt to patch any uninstrumented classes in sys.modules.

    This enables us to not care about the order of imports and sentry_sdk.init()
    in user code. If e.g. the Flask class had been imported before sentry_sdk
    was init()ed (and therefore before the OTel instrumentation ran), it would
    not be instrumented. This function goes over remaining uninstrumented
    occurrences of the class in sys.modules and replaces them with the
    instrumented class.

    Since this is looking for exact matches, it will not work in some scenarios
    (e.g. if someone is not using the specific class explicitly, but rather
    inheriting from it). In those cases it's still necessary to sentry_sdk.init()
    before importing anything that's supposed to be instrumented.
    z9[OTel] Failed to check if class has been instrumented: %szopentelemetry.NÚ
sentry_sdkz'[OTel] Additionally patching %s from %s)ÚlistÚkeysr+   r-   r.   r/   r	   r   r$   Ú
startswithÚsysÚmodulesÚcopyr,   Úbuiltin_module_namesÚvarsÚsetattr)
r   Úinstrumented_classesr1   Úoriginal_pathÚclsÚmodule_nameÚmoduler3   Úvar_nameÚvars
             r!   r   r   b   sq  € ð$ ÐäÐ(×-Ñ-Ó/Ó0ò ,ˆÜ-¨gÑ6ˆð	Ü! -Ó0ˆCð �~‰~×(Ñ(Ð)9Ô:Ø  Ð)Øà(+Ð˜WÒ%ð#,ñ&  Øô  #Ÿ{™{×/Ñ/Ó1×7Ñ7Ó9ò MÑˆ�Và×"Ñ" <Ô0Øœc×6Ñ6Ñ6àà%5×%;Ñ%;Ó%=ò 		MÑ!ˆG�\Ü!% f£×!2Ñ!2Ó!4×!:Ñ!:Ó!<ò M‘�˜#Ø˜,Ó&Ü—L‘LØAØ$Ø#ôô ˜F HÐ.BÀ7Ñ.KÕLñMñ		MñMøô% ¤Ð,ò 	Ü�L‰LØKØôð ! Ð)Úð	ús   ©D*Ä*(EÅEc                 ó^   — | j                  dd¬«      }t        t        |d   «      |d   «      S )Nú.é   )Úmaxsplitr   éÿÿÿÿ)ÚrsplitÚgetattrr   )ÚpathÚpartss     r!   r-   r-       s.   € à�K‰K˜ aˆKÓ(€EÜ”=  q¡Ó*¨E°"©IÓ6Ð6r)   c                  óš   — t        «       } | j                  t        «       «       t        j                  | «       t        t        «       «       y )N)r   Úadd_span_processorr   r   Úset_tracer_providerr   r   )Úproviders    r!   r   r   ¦   s6   € äÓ€Hà×ÑÔ 3Ó 5Ô6ä	×Ñ˜hÔ'äÔ'Ó)Õ*r)   )#Ú__doc__r9   Ú	importlibr   Úsentry_sdk.integrationsr   r   Ú4sentry_sdk.integrations.opentelemetry.span_processorr   Ú0sentry_sdk.integrations.opentelemetry.propagatorr   Úsentry_sdk.integrations.modulesr   Úsentry_sdk.utilsr	   Úsentry_sdk._typesr
   r   r   Ú8opentelemetry.instrumentation.auto_instrumentation._loadr   r   Úopentelemetry.propagater   Úopentelemetry.sdk.tracer   r/   Útypingr   r+   r   r   r   r-   r   r(   r)   r!   ú<module>r_      s”   ðñó
 Ý #ç =Ý TÝ MÝ BÝ #Ý +ð	6Ý#÷õ ;Ý6ñ Ýð !ØñÐ ôM˜{ô MòBò2;Mò|7ó+øð] ò 6Ù
Ð4Ó
5Ð5ð6ús   ´A3 Á3B