o
    0 i9                     @   s   d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
 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 W n eyO   edw d dlmZ erdd dlmZmZmZmZ dd ZdddZG dd deZ dS )    )IntegrationDidNotEnable)%register_external_propagation_context)loggerDsn)VERSIONEndpointType)trace)set_global_textmap)TracerProvider)BatchSpanProcessor)OTLPSpanExporter)SentryPropagatorz+opentelemetry-distro[otlp] is not installed)TYPE_CHECKING)OptionalDictAnyTuplec                  C   s@   t   } | jt jks| jt jkrdS t | jt | jfS )zC
    Get the (trace_id, span_id) from opentelemetry if exists.
    N)	r	   Zget_current_spanZget_span_contextZtrace_idZINVALID_TRACE_IDZspan_idZINVALID_SPAN_IDZformat_trace_idZformat_span_id)ctx r   h/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/otlp.pyotel_propagation_context   s   r   Nc                 C   s   t  }t|tstd t }t | d }d }| r:t| dt	 }|
tj}d| i}td|  t||d}t|}|| d S )Nz?[OTLP] No TracerProvider configured by user, creating a new onezsentry.python/zX-Sentry-Authz[OTLP] Sending traces to )endpointheaders)r	   Zget_tracer_provider
isinstancer   r   debugZset_tracer_providerr   Zto_authr   Zget_api_urlr   ZOTLP_TRACESZ	to_headerr   r   Zadd_span_processor)dsnZtracer_providerr   r   authZotlp_exporterZspan_processorr   r   r   setup_otlp_exporter$   s   


r   c                   @   s0   e Zd ZdZd
ddZedd Zddd	ZdS )OTLPIntegrationZotlpTc                 C   s   || _ || _d S N)r   setup_propagator)selfr   r!   r   r   r   __init__=   s   
zOTLPIntegration.__init__c                   C   s   t d tt d S )Nz.[OTLP] Setting up trace linking for all events)r   r   r   r   r   r   r   r   
setup_onceB   s   
zOTLPIntegration.setup_onceNc                 C   sL   | j rtd |r|dnd }t | | jr$td tt  d S d S )Nz[OTLP] Setting up OTLP exporterr   z4[OTLP] Setting up propagator for distributed tracing)r   r   r   getr!   r
   r   )r"   optionsr   r   r   r   setup_once_with_optionsH   s   

z'OTLPIntegration.setup_once_with_options)TTr    )__name__
__module____qualname__
identifierr#   staticmethodr$   r'   r   r   r   r   r   :   s    

r   r    )!Zsentry_sdk.integrationsr   r   Zsentry_sdk.scoper   Zsentry_sdk.utilsr   r   Zsentry_sdk.constsr   r   Zopentelemetryr	   Zopentelemetry.propagater
   Zopentelemetry.sdk.tracer   Zopentelemetry.sdk.trace.exportr   Z5opentelemetry.exporter.otlp.proto.http.trace_exporterr   Z0sentry_sdk.integrations.opentelemetry.propagatorr   ImportErrortypingr   r   r   r   r   r   r   r   r   r   r   r   <module>   s(    
