
    Zj/                       U d dl mZ d dlZd dl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 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 d dlmZm Z m!Z!m"Z"m#Z#mZmZ d dl$m%Z%m&Z&m'Z'mZ d dl(m)Z)m*Z*m+Z+mZm,Z,  ej-        e.          Z/ e+e*          Z0d2dZ1d3dZ2e1e2d dZ3de4d<   d4dZ5d5d"Z6d6d%Z7d7d'Z8d8d*Z9	 d9d:d/Z:	 d9d;d1Z;dS )<    )annotationsN)trace)_map_compression_parse_headersload_entry_point)ConfigurationError)OtlpGrpcExporter)OtlpHttpExporter)ParentBasedSampler)Sampler)SpanExporter)
SpanLimits)SpanProcessor)TracerProvider)Resource))_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT(_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT(_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT$_DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMIT#_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMITr   r   )BatchSpanProcessorConsoleSpanExporterSimpleSpanProcessorr   )
ALWAYS_OFF	ALWAYS_ONParentBasedr   TraceIdRatioBased)rootconfigOtlpHttpExporterConfigreturnr   c                   	 ddl m} ddlm} n"# t          $ r}t          d          |d}~ww xY wt          | j        |d          }t          | j	        | j
                  }| j        
| j        dz  nd} || j        |||	          S )
z.Create an OTLP HTTP span exporter from config.r   )CompressionOTLPSpanExporterzotlp_http span exporter requires 'opentelemetry-exporter-otlp-proto-http'. Install it with: pip install opentelemetry-exporter-otlp-proto-httpNT)allow_deflate     @@endpointheaderstimeoutcompression)&opentelemetry.exporter.otlp.proto.httpr#   5opentelemetry.exporter.otlp.proto.http.trace_exporterr%   ImportErrorr   r   r,   r   r*   headers_listr+   r)   )r   r#   r%   excr,   r*   r+   s          n/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/sdk/_configuration/_tracer_provider.py_create_otlp_http_span_exporterr3   E   s    	
 	
 	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
     R
 
 	 #Kt  K V^V-@AAG+1>+Ev~&&4G	   s    
.).OtlpGrpcExporterConfigc                   	 ddl }ddlm} n"# t          $ r}t	          d          |d}~ww xY wt          | j        |j                  }t          | j	        | j
                  }| j        
| j        dz  nd} || j        |||          S )z.Create an OTLP gRPC span exporter from config.r   Nr$   zotlp_grpc span exporter requires 'opentelemetry-exporter-otlp-proto-grpc'. Install it with: pip install opentelemetry-exporter-otlp-proto-grpcr'   r(   )grpc5opentelemetry.exporter.otlp.proto.grpc.trace_exporterr%   r/   r   r   r,   r#   r   r*   r0   r+   r)   )r   r6   r%   r1   r,   r*   r+   s          r2   _create_otlp_grpc_span_exporterr8   e   s    	
 	
 	
 	
 	
 	
 	
     R
 
 	 #6#5t7GHHKV^V-@AAG+1>+Ev~&&4G	   s   
 
,',c                    t                      S N)r   )_s    r2   <lambda>r<      s    ,..     )	otlp_http	otlp_grpcconsoledict_SPAN_EXPORTER_REGISTRYSpanExporterConfigc                t   | j         t          d          t                                          D ]%\  }}t	          | |d          }| ||          c S &| j        rNt          t          | j                                                            \  }} t          d|          di |pi S t          d          )a4  Create a span exporter from config.

    Known exporter types are checked via typed fields on the SpanExporter
    dataclass. Unknown exporter names captured in additional_properties
    by the @_additional_properties decorator are loaded via the
    ``opentelemetry_traces_exporter`` entry point group.
    NzJotlp_file_development span exporter is experimental and not yet supported.opentelemetry_traces_exporterzcNo exporter type specified in span exporter config. Supported types: otlp_http, otlp_grpc, console. )	otlp_file_developmentr   rB   itemsgetattradditional_propertiesnextiterr   )r   namefactoryvalueplugin_configs        r2   _create_span_exporterrQ      s     #/ %
 
 	
 16688 " "gd++75>>!!! # 
"4(D(J(J(L(L#M#MNNmF ?FF 
 
"
 
 	
 	:  r=   SpanProcessorConfig(BatchSpanProcessor | SimpleSpanProcessorc                2   | j         Ut          | j         j                  }t          || j         j        | j         j        | j         j        | j         j                  S | j        &t          t          | j        j                            S t          d          )z$Create a span processor from config.N)max_queue_sizeschedule_delay_millismax_export_batch_sizeexport_timeout_milliszUNo processor type specified in span processor config. Supported types: batch, simple.)batchrQ   exporterr   rU   schedule_delayrW   export_timeoutsimpler   r   )r   rZ   s     r2   _create_span_processorr^      s     |()>??!!<6"(,"="(,"D"(,"=
 
 
 	
 } "!&-"899
 
 	
 	*  r=   SamplerConfigr   c                b   | j         t          S | j        t          S | j        | j        j        }t          ||nd          S | j        t          | j                  S | j	        r9t          t          | j	                            } t          d|                      S t          d| d          )a  Create a sampler from config.

    Known sampler types are checked via typed fields on the Sampler
    dataclass. Unknown sampler names captured in additional_properties
    by the @_additional_properties decorator are loaded via the
    ``opentelemetry_sampler`` entry point group.
    Ng      ?opentelemetry_samplerz/Unknown or unsupported sampler type in config: zM. Supported types: always_on, always_off, trace_id_ratio_based, parent_based.)	always_onr   
always_offr   trace_id_ratio_basedratior   parent_based_create_parent_based_samplerrJ   rK   rL   r   r   )r   re   rM   s      r2   _create_samplerrh      s     #$".+1 %*;EEE&+F,?@@@# AD56677> 7>>@@@
	V& 	V 	V 	V  r=   ParentBasedSamplerConfigc                V   | j         t          | j                   nt          }d|i}| j        t          | j                  |d<   | j        t          | j                  |d<   | j        t          | j                  |d<   | j        t          | j                  |d<   t          di |S )zUCreate a ParentBased sampler from config, applying SDK defaults for absent delegates.Nr   remote_parent_sampledremote_parent_not_sampledlocal_parent_sampledlocal_parent_not_sampledrF   )r   rh   r   rk   rl   rm   rn   r   )r   r   kwargss      r2   rg   rg      s     )/(?$$$Y 	 D>F#/*9(+
 +
&' '3.=,/
 /
*+ ".)8'*
 *
%& &2-<+.
 .
)*      r=   SpanLimitsConfigr   c                    t          | j        | j        nt          | j        | j        nt          | j        | j        nt          | j        | j        nt          | j	        | j	        nt          | j                  S )u   Create SpanLimits from config.

    Absent fields use the OTel spec defaults (128 for counts, unlimited for lengths).
    Explicit values suppress env-var reading — matching Java SDK behavior.
    N)max_span_attributes
max_events	max_linksmax_event_attributesmax_link_attributesmax_attribute_length)r   attribute_count_limitr   event_count_limitr   link_count_limitr   event_attribute_count_limitr   link_attribute_count_limitr   attribute_value_length_limit)r   s    r2   _create_span_limitsr~      s      +7 ((9 '3 $$5 &2 ##4 1= ..: 0< --9#@5   r=   TracerProviderConfig | NoneresourceResource | Noner   c                b   | | j         t          | j                   nt          }| | j        t	          | j                  n,t          t          t          t          t          t                    }t          |||          }| ,| j        D ]$}|                    t          |                     %|S )a  Create an SDK TracerProvider from declarative config.

    Does NOT read OTEL_TRACES_SAMPLER, OTEL_SPAN_*_LIMIT, or any other env vars
    for values that are explicitly controlled by the config. Absent config values
    use OTel spec defaults (not env vars), matching Java SDK behavior.

    Args:
        config: TracerProvider config from the parsed config file, or None.
        resource: Resource to attach to the provider.

    Returns:
        A configured TracerProvider.
    N)rr   rs   rt   ru   rv   )r   samplerspan_limits)r   rh   _DEFAULT_SAMPLERlimitsr~   r   r   r   r   r   r   r   
processorsadd_span_processorr^   )r   r   r   r   providerproc_configs         r2   create_tracer_providerr     s    & &."< 	'''  &-"; 	FM*** H;9!J H
 
 
    H !, 	M 	MK''(>{(K(KLLLLOr=   Nonec                R    | dS t          j        t          | |                     dS )u  Configure the global TracerProvider from declarative config.

    When config is None (tracer_provider section absent from config file),
    the global is not set — matching Java/JS SDK behavior and the spec's
    "a noop tracer provider is used" default.

    Args:
        config: TracerProvider config from the parsed config file, or None.
        resource: Resource to attach to the provider.
    N)r   set_tracer_providerr   )r   r   s     r2   configure_tracer_providerr   B  s0     ~	4VXFFGGGGGr=   )r   r    r!   r   )r   r4   r!   r   )r   rC   r!   r   )r   rR   r!   rS   )r   r_   r!   r   )r   ri   r!   r   )r   rp   r!   r   r:   )r   r   r   r   r!   r   )r   r   r   r   r!   r   )<
__future__r   loggingopentelemetryr   (opentelemetry.sdk._configuration._commonr   r   r   ,opentelemetry.sdk._configuration._exceptionsr   'opentelemetry.sdk._configuration.modelsr	   r4   r
   r    r   ri   r   r_   r   rC   r   rp   r   rR   r   TracerProviderConfigopentelemetry.sdk.resourcesr   opentelemetry.sdk.tracer   r   r   r   r   opentelemetry.sdk.trace.exportr   r   r    opentelemetry.sdk.trace.samplingr   r   r   r   	getLogger__name___loggerr   r3   r8   rB   __annotations__rQ   r^   rh   rg   r~   r   r   rF   r=   r2   <module>r      s   # " " " " " "                
 L K K K K K                                         1 0 0 0 0 0                                          '
H
%
% ;I...    @   < 10..! !        8   .   4! ! ! !2! ! ! !L !%, , , , ,b !%H H H H H H Hr=   