§
    xÅjö  ã                   óØ  — d dl mZmZ d dlmZmZ d dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZmZmZmZ 	 d dlmZmZmZ d d	lmZ d d
lm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'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 n# e3$ r  ed¦  «        ‚w xY wd dl4m5Z5 e5rd dl4m6Z6m7Z7m8Z8m9Z9 d%d„Z:	 d&	 	 	 	 	 d'd„Z;da<d(d„Z= G d„ de2¦  «        Z>d d!de?fd"„Z@ G d#„ d$e¦  «        ZAdS ))é    )Úcapture_eventÚ
get_client)ÚVERSIONÚEndpointType)ÚDidNotEnableÚIntegration)Ú%register_external_propagation_context)ÚBAGGAGE_HEADER_NAMEÚSENTRY_TRACE_HEADER_NAME)ÚBaggage)ÚDsnÚcapture_internal_exceptionsÚevent_from_exceptionÚlogger)ÚContextÚget_currentÚ	get_value)ÚOTLPSpanExporter)Úset_global_textmap)ÚCarrierTÚSetterÚdefault_setter)ÚSpanÚTracerProvider)ÚBatchSpanProcessor)ÚINVALID_SPAN_IDÚINVALID_TRACE_IDÚSpanContextÚformat_span_idÚformat_trace_idÚget_current_spanÚget_tracer_providerÚset_tracer_provider)ÚSENTRY_BAGGAGE_KEY)ÚSentryPropagatorz+opentelemetry-distro[otlp] is not installed)ÚTYPE_CHECKING)ÚAnyÚDictÚOptionalÚTupleÚreturnúOptional[Tuple[str, str]]c                  óÖ   — t          ¦   «                              ¦   «         } | j        t          k    s| j        t
          k    rdS t          | j        ¦  «        t          | j        ¦  «        fS )zC
    Get the (trace_id, span_id) from opentelemetry if exists.
    N)r!   Úget_span_contextÚtrace_idr   Úspan_idr   r    r   )Úctxs    úMC:\Projects\Historical\venv\Lib\site-packages\sentry_sdk/integrations/otlp.pyÚotel_propagation_contextr3   6   sY   € õ Ñ
Ô
×
-Ò
-Ñ
/Ô
/€Cà
„|Õ'Ò'Ð'¨3¬;½/Ò+IÐ+IØˆtå˜CœLÑ)Ô)­>¸#¼+Ñ+FÔ+FÐGÐGó    NÚdsnúOptional[str]Úcollector_urlc                 óH  — t          ¦   «         }t          |t          ¦  «        s1t          j        d¦  «         t          ¦   «         }t          |¦  «         d }d }|r|}t          j        d|› �¦  «         nx| rvt          | ¦  «                             dt          › �¦  «        }| 	                    t          j        ¦  «        }d|                     ¦   «         i}t          j        d|› �¦  «         t          ||¬¦  «        }t          |¦  «        }|                     |¦  «         d S )Nz?[OTLP] No TracerProvider configured by user, creating a new onez&[OTLP] Sending traces to collector at zsentry.python/zX-Sentry-Authz[OTLP] Sending traces to )ÚendpointÚheaders)r"   Ú
isinstancer   r   Údebugr#   r   Úto_authr   Úget_api_urlr   ÚOTLP_TRACESÚ	to_headerr   r   Úadd_span_processor)r5   r7   Útracer_providerr9   r:   ÚauthÚotlp_exporterÚspan_processors           r2   Úsetup_otlp_traces_exporterrF   B   s$  € õ *Ñ+Ô+€Oå�o¥~Ñ6Ô6ð -ÝŒÐVÑWÔWÐWÝ(Ñ*Ô*ˆÝ˜OÑ,Ô,Ð,à€HØ€GØð =Ø ˆÝŒÐH¸hÐHÐHÑIÔIÐIÐIØ	ð =Ý�3‰xŒx×ÒÐ :µÐ :Ð :Ñ;Ô;ˆØ×#Ò#¥LÔ$<Ñ=Ô=ˆØ" D§N¢NÑ$4Ô$4Ð5ˆÝŒÐ;°Ð;Ð;Ñ<Ô<Ð<å$¨hÀÐHÑHÔH€MÝ'¨Ñ6Ô6€NØ×&Ò& ~Ñ6Ô6Ð6Ð6Ð6r4   Fc                  ón   ‡— t           j        Št          rdS 	 	 	 	 	 	 	 	 	 	 dˆfd
„} | t           _        dadS )ze
    Intercept otel's Span.record_exception to automatically capture those exceptions in Sentry.
    NÚselfr   Ú	exceptionÚBaseExceptionÚargsr'   Úkwargsr+   c                 óT  •— t          ¦   «                              t          ¦  «        }|rq|j        rjt	          ¦   «         5  t          |t          ¦   «         j        t          j        ddœ¬¦  «        \  }}t          ||¬¦  «         d d d ¦  «         n# 1 swxY w Y    ‰| |g|¢R i |¤Ž d S )NF)ÚtypeÚhandled)Úclient_optionsÚ	mechanism)Úhint)	r   Úget_integrationÚOTLPIntegrationÚcapture_exceptionsr   r   ÚoptionsÚ
identifierr   )rH   rI   rK   rL   Úotlp_integrationÚeventrR   Ú_original_record_exceptions          €r2   Ú _sentry_patched_record_exceptionzBsetup_capture_exceptions.<locals>._sentry_patched_record_exceptioni   s  ø€ õ &™<œ<×7Ò7½ÑHÔHÐØð 	0Ð 0Ô Cð 	0Ý,Ñ.Ô.ð 0ð 0Ý2ØÝ#-¡<¤<Ô#7Ý'6Ô'AÈeÐTÐTðñ ô ‘��tõ
 ˜e¨$Ð/Ñ/Ô/Ð/ð0ð 0ð 0ñ 0ô 0ð 0ð 0ð 0ð 0ð 0ð 0øøøð 0ð 0ð 0ð 0ð 	#Ð" 4¨ÐD°TÐDÐDÐD¸VÐDÐDÐDÐDÐDs   ¿ABÂBÂBT)
rH   r   rI   rJ   rK   r'   rL   r'   r+   N)r   Úrecord_exceptionÚ_sentry_patched_exception)r[   rZ   s    @r2   Úsetup_capture_exceptionsr^   _   s‚   ø€ õ
 "&Ô!6Ðå ð ØˆðEØðEØ!0ðEØ9>ðEØJOðEà	ðEð Eð Eð Eð Eð Eð =…DÔØ $ÐÐÐr4   c                   ó.   — e Zd ZdZdef	 	 	 	 	 	 	 dd
„ZdS )ÚSentryOTLPPropagatora›  
    We need to override the inject of the older propagator since that
    is SpanProcessor based.

    !!! Note regarding baggage:
    We cannot meaningfully populate a new baggage as a head SDK
    when we are using OTLP since we don't have any sort of transaction semantic to
    track state across a group of spans.

    For incoming baggage, we just pass it on as is so that case is correctly handled.
    NÚcarrierr   ÚcontextúOptional[Context]ÚsetterúSetter[CarrierT]r+   c                 óð  — t          ¦   «                              t          ¦  «        }|€d S |€t          ¦   «         }t	          |¦  «        }|                     ¦   «         }|j        sd S t          |¦  «        }|                     |t          |¦  «         t          t          |¦  «        }|�It          |t          ¦  «        r6|                     ¦   «         }	|	r"|                     |t          |	¦  «         d S d S d S d S ©N)r   rS   rT   r   r!   r.   Úis_validÚ_to_traceparentÚsetr   r   r$   r;   r   Ú	serializer
   )
rH   ra   rb   rd   rX   Úcurrent_spanÚcurrent_span_contextÚsentry_traceÚbaggageÚbaggage_datas
             r2   ÚinjectzSentryOTLPPropagator.inject‰   sÿ   € õ &™<œ<×7Ò7½ÑHÔHÐØÐ#ØˆFàˆ?Ý!‘m”mˆGå'¨Ñ0Ô0ˆØ+×<Ò<Ñ>Ô>Ðà#Ô,ð 	ØˆFå&Ð';Ñ<Ô<ˆØ�
Š
�7Õ4°lÑCÔCÐCåÕ.°Ñ8Ô8ˆØÐ¥:¨gµwÑ#?Ô#?ÐØ"×,Ò,Ñ.Ô.ˆLØð GØ—
’
˜7Õ$7¸ÑFÔFÐFÐFÐFð ÐÐÐðGð Gr4   )ra   r   rb   rc   rd   re   r+   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rq   © r4   r2   r`   r`   |   sj   € € € € € ð
ð 
ð (,Ø%3ð	GàðGð %ðGð #ð	Gð
 
ðGð Gð Gð Gð Gð Gr4   r`   Úspan_contextr   c                 ó†   — t          | j        ¦  «        }t          | j        ¦  «        }| j        j        }|› d|› d|rdnd› �S )z<
    Helper method to generate the sentry-trace header.
    ú-Ú1Ú0)r   r0   r    r/   Útrace_flagsÚsampled)rw   r0   r/   r}   s       r2   ri   ri   ¦   sT   € õ ˜\Ô1Ñ2Ô2€GÝ˜|Ô4Ñ5Ô5€HØÔ&Ô.€GàÐ<Ð<˜Ð<Ð<¨'Ð#: 3 3°sÐ<Ð<Ð<r4   c                   óf   — e Zd ZdZdZ	 	 	 	 ddeddd	ed
eddf
d„Zedd„¦   «         Z	 d	 	 	 dd„Z	dS )rT   a´  
    Automatically setup OTLP ingestion from the DSN.

    :param setup_otlp_traces_exporter: Automatically configure an Exporter to send OTLP traces from the DSN, defaults to True.
        Set to False to setup the TracerProvider manually.
    :param collector_url: URL of your own OpenTelemetry collector, defaults to None.
        When set, the exporter will send traces to this URL instead of the Sentry OTLP endpoint derived from the DSN.
    :param setup_propagator: Automatically configure the Sentry Propagator for Distributed Tracing, defaults to True.
        Set to False to configure propagators manually or to disable propagation.
    :param capture_exceptions: Intercept and capture exceptions on the OpenTelemetry Span in Sentry as well, defaults to False.
        Set to True to turn on capturing but be aware that since Sentry captures most exceptions, duplicate exceptions might be dropped by DedupeIntegration in many cases.
    ÚotlpTNFrF   r7   r6   Úsetup_propagatorrU   r+   c                 ó>   — || _         || _        || _        || _        d S rg   )rF   r7   r€   rU   )rH   rF   r7   r€   rU   s        r2   Ú__init__zOTLPIntegration.__init__Á   s+   € ð +EˆÔ'Ø*ˆÔØ 0ˆÔØ"4ˆÔÐÐr4   c                  óV   — t          j        d¦  «         t          t          ¦  «         d S )Nz.[OTLP] Setting up trace linking for all events)r   r<   r	   r3   rv   r4   r2   Ú
setup_oncezOTLPIntegration.setup_onceÍ   s(   € åŒÐEÑFÔFÐFÝ-Õ.FÑGÔGÐGÐGÐGr4   rV   úOptional[Dict[str, Any]]c                 ó"  — | j         rCt          j        d¦  «         |r|                     d¦  «        nd }t          || j        ¬¦  «         | j        r/t          j        d¦  «         t          t          ¦   «         ¦  «         t          ¦   «          d S )Nz[OTLP] Setting up OTLP exporterr5   )r7   z4[OTLP] Setting up propagator for distributed tracing)	rF   r   r<   Úgetr7   r€   r   r`   r^   )rH   rV   r5   s      r2   Úsetup_once_with_optionsz'OTLPIntegration.setup_once_with_optionsÒ   s•   € ð Ô*ð 	NÝŒLÐ:Ñ;Ô;Ð;Ø9@Ð#J 7§;¢;¨uÑ#5Ô#5Ð#5ÀdˆCÝ& s¸$Ô:LÐMÑMÔMÐMàÔ ð 	7ÝŒLÐOÑPÔPÐPåÕ3Ñ5Ô5Ñ6Ô6Ð6å Ñ"Ô"Ð"Ð"Ð"r4   )TNTF©r+   Nrg   )rV   r…   r+   N)
rr   rs   rt   ru   rW   Úboolr‚   Ústaticmethodr„   rˆ   rv   r4   r2   rT   rT   ±   sÉ   € € € € € ðð ð €Jð ,0Ø)-Ø!%Ø#(ð
5ð 
5à$(ð
5ð 'ð
5ð ð	
5ð
 !ð
5ð 
ð
5ð 
5ð 
5ð 
5ð ðHð Hð Hñ „\ðHð
 59ð#Ø1ð#à	ð#ð #ð #ð #ð #ð #r4   rT   )r+   r,   )NN)r5   r6   r7   r6   r+   Nr‰   )BÚ
sentry_sdkr   r   Úsentry_sdk.constsr   r   Úsentry_sdk.integrationsr   r   Úsentry_sdk.scoper	   Úsentry_sdk.tracingr
   r   Úsentry_sdk.tracing_utilsr   Úsentry_sdk.utilsr   r   r   r   Úopentelemetry.contextr   r   r   Ú5opentelemetry.exporter.otlp.proto.http.trace_exporterr   Úopentelemetry.propagater   Ú!opentelemetry.propagators.textmapr   r   r   Úopentelemetry.sdk.tracer   r   Úopentelemetry.sdk.trace.exportr   Úopentelemetry.tracer   r   r   r   r    r!   r"   r#   Ú,sentry_sdk.integrations.opentelemetry.constsr$   Ú0sentry_sdk.integrations.opentelemetry.propagatorr%   ÚImportErrorÚtypingr&   r'   r(   r)   r*   r3   rF   r]   r^   r`   Ústrri   rT   rv   r4   r2   ú<module>rŸ      sƒ  ðØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø BÐ BÐ BÐ BÐ BÐ Bðð ð ð ð ð ð ð ð -Ð ,Ð ,Ð ,Ð ,Ð ,ðð ð ð ð ð ð ð ð ð ð ð ðFðð ð ð ð ð ð ð ð ð ð
 WÐVÐVÐVÐVÐVØ:Ð:Ð:Ð:Ð:Ð:ðð ð ð ð ð ð ð ð ð ð
 =Ð<Ð<Ð<Ð<Ð<Ð<Ð<ØAÐAÐAÐAÐAÐAð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð PÐOÐOÐOÐOÐOØQÐQÐQÐQÐQÐQÐQøØð Fð Fð FØ
ˆ,ÐDÑ
EÔ
EÐEðFøøøð !Ð  Ð  Ð  Ð  Ð  àð 2Ø1Ð1Ð1Ð1Ð1Ð1Ð1Ð1Ð1Ð1Ð1Ð1ð	Hð 	Hð 	Hð 	Hð CGð7Ø	ð7Ø0?ð7à	ð7ð 7ð 7ð 7ð4 "Ð ð%ð %ð %ð %ð:'Gð 'Gð 'Gð 'Gð 'GÐ+ñ 'Gô 'Gð 'GðT= -ð =°Cð =ð =ð =ð =ð.#ð .#ð .#ð .#ð .#�kñ .#ô .#ð .#ð .#ð .#s   ºAB	 Â	B