
    Zj
E                    v   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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$m%Z%m&Z&m'Z'mZm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/mZm0Z0mZm1Z1 d dl2mZm3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m!Z! d dl9m:Z:  ej;        e<          Z=dZ>dZ?ej@        e&ejA        e,ejB        e'ejC        e-ejD        e(ejE        e)ejF        e*iZGdeHd<   dEdZIdFd ZJdGd$ZKdHd'ZLdId*ZMdJd,ZNdKd.ZOeNeOeMd/ZPd0eHd1<   dLd3ZQdMd6ZRdNd9ZSdOd=ZT	 dPdQdBZU	 dPdRdDZVdS )S    )annotationsN)metrics)_map_compression_parse_headersload_entry_point)ConfigurationError)Aggregation)ConsoleMetricExporter)ExemplarFilter)#ExporterDefaultHistogramAggregationExporterTemporalityPreferenceInstrumentType)MeterProvider)MetricReader)OtlpGrpcMetricExporter)OtlpHttpMetricExporter)PeriodicMetricReader)PushMetricExporter)View)AlwaysOffExemplarFilterAlwaysOnExemplarFilterCounter	Histogramr   ObservableCounterObservableGaugeObservableUpDownCounterTraceBasedExemplarFilterUpDownCounter_Gauge)AggregationTemporalityr
   MetricExporterr   PeriodicExportingMetricReader)r	   DefaultAggregationDropAggregation"ExplicitBucketHistogramAggregation%ExponentialBucketHistogramAggregationLastValueAggregationSumAggregationr   )Resourcei`  i0u  zdict[InstrumentType, type]_INSTRUMENT_TYPE_MAPpref$ExporterTemporalityPreference | Nonereturn"dict[type, AggregationTemporality]c                   | | t           j        k    rht          t          j        t
          t          j        t          t          j        t          t          j        t          t          j        t          t          j        iS | t           j
        k    rht          t          j        t
          t          j        t          t          j        t          t          j        t          t          j        t          t          j        iS | t           j        k    rht          t          j        t
          t          j        t          t          j        t          t          j        t          t          j        t          t          j        iS t          d|  d          )u   Map a temporality preference to an explicit preferred_temporality dict.

    Always returns an explicit dict to suppress OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE.
    Default (None or cumulative) → all instruments CUMULATIVE.
    Nz$Unsupported temporality preference 'z3'. Supported values: cumulative, delta, low_memory.)r   
cumulativer   r    
CUMULATIVEr   r   r   r   r   deltaDELTA
low_memoryr   r+   s    m/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/sdk/_configuration/_meter_provider.py_map_temporalityr7   e   s#    |t<GGG+61<-85@#%;%F3>
 	
 ,222+11<-35;#%;%F3>
 	
 ,777+11<-35@#%;%F3>
 	
 	;t 	; 	; 	;      *ExporterDefaultHistogramAggregation | Nonedict[type, Aggregation]c                    | | t           j        k    rt          t                      iS | t           j        k    rt          t                      iS t          d|  d          )u  Map a histogram aggregation preference to an explicit preferred_aggregation dict.

    Always returns an explicit dict to suppress
    OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION.
    Default (None or explicit_bucket_histogram) → ExplicitBucketHistogramAggregation.
    Nz+Unsupported default histogram aggregation 'zS'. Supported values: explicit_bucket_histogram, base2_exponential_bucket_histogram.)r   explicit_bucket_histogramr   r%   "base2_exponential_bucket_histogramr&   r   r5   s    r6   _map_histogram_aggregationr>      s     	.HI I =??@@.Q	R 	R @BBCC
	[d 	[ 	[ 	[  r8   configAggregationConfigr	   c                   | j         t                      S | j        t                      S | j        3t          | j        j        | j        j        | j        j        nd          S | j        Di }| j        j	        | j        j	        |d<   | j        j
        | j        j
        |d<   t          di |S | j        t                      S | j        t                      S t!          d| d          )	zICreate an SDK Aggregation from config, passing through detail parameters.NT)
boundariesrecord_min_maxmax_size	max_scalez3Unknown or unsupported aggregation type in config: zq. Supported types: default, drop, explicit_bucket_histogram, base2_exponential_bucket_histogram, last_value, sum. )defaultr#   dropr$   r<   r%   rB   rC   r=   rD   rE   r&   
last_valuer'   sumr(   r   )r?   kwargss     r6   _create_aggregationrL      s)   ~!!###{   '317B 3BN 0??
 
 
 	
 0<4=I9B : 4>J9C ; 5>>v>>>$#%%%z
	?f 	? 	? 	?  r8   
ViewConfigr   c                   | j         }| j        }d}|j        8t                              |j                  }|t          d|j                  d}|j        K|j        j        rt          	                    d           |j        j
        t          |j        j
                  }d}|j        t          |j                  }t          ||j        |j        |j        |j        |j        |j        |j        ||
  
        S )zCreate an SDK View from config.NzUnknown instrument type: zdattribute_keys.excluded is not supported by the Python SDK View; the exclusion list will be ignored.)
instrument_typeinstrument_name
meter_namemeter_versionmeter_schema_urlinstrument_unitnamedescriptionattribute_keysaggregation)selectorstreamrO   r*   getr   rW   excluded_loggerwarningincludedsetrX   rL   r   rP   rQ   rR   rS   unitrU   rV   )r?   rY   rZ   rO   rW   rX   s         r6   _create_viewrb      s   H]FO+.2283KLL"$HH,DHH   '+N( ) 	OO6    )5 !6!?@@NK%)&*<==' 0&,!2 [&%   r8   ConsoleMetricExporterConfigr!   c                t    t          | j                  }t          | j                  }t	          ||          S )z+Create a ConsoleMetricExporter from config.)preferred_temporalitypreferred_aggregation)r7   temporality_preferencer>   default_histogram_aggregationr
   )r?   re   rf   s      r6   _create_console_metric_exporterri      sJ     -V-JKK6,  !33   r8   OtlpHttpMetricExporterConfigc                f   	 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}t          | j                  }t          | j                  } || j        |||||	          S )
z0Create an OTLP HTTP metric exporter from config.r   )CompressionOTLPMetricExporterzotlp_http metric exporter requires 'opentelemetry-exporter-otlp-proto-http'. Install it with: pip install opentelemetry-exporter-otlp-proto-httpNT)allow_deflate     @@endpointheaderstimeoutcompressionre   rf   )&opentelemetry.exporter.otlp.proto.httprl   6opentelemetry.exporter.otlp.proto.http.metric_exporterrn   ImportErrorr   r   ru   r   rs   headers_listrt   r7   rg   r>   rh   rr   )	r?   rl   rn   excru   rs   rt   re   rf   s	            r6   !_create_otlp_http_metric_exporterr{     s+   	
 	
 	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
     R
 
 	 #Kt  K V^V-@AAG+1>+Ev~&&4G,V-JKK6,  33   s    
.).OtlpGrpcMetricExporterConfigc                h   	 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}t          | j                  }t          | j                  } || j        |||||          S )z0Create an OTLP gRPC metric exporter from config.r   Nrm   zotlp_grpc metric exporter requires 'opentelemetry-exporter-otlp-proto-grpc'. Install it with: pip install opentelemetry-exporter-otlp-proto-grpcrp   rq   )grpc6opentelemetry.exporter.otlp.proto.grpc.metric_exporterrn   rx   r   r   ru   rl   r   rs   ry   rt   r7   rg   r>   rh   rr   )	r?   r~   rn   rz   ru   rs   rt   re   rf   s	            r6   !_create_otlp_grpc_metric_exporterr   *  s   	
 	
 	
 	
 	
 	
 	
     R
 
 	 #6#5t7GHHKV^V-@AAG+1>+Ev~&&4G,V-JKK6,  33   s   
 
,',)	otlp_http	otlp_grpcconsoledict_METRIC_EXPORTER_REGISTRYPushMetricExporterConfigc                t   | j         t          d          t                                          D ]%\  }}t	          | |d          }| ||          c S &| j        rNt          t          | j                                                            \  }} t          d|          di |pi S t          d          )aB  Create a push metric exporter from config.

    Known exporter types are checked via typed fields on the PushMetricExporter
    dataclass. Unknown exporter names captured in additional_properties
    by the @_additional_properties decorator are loaded via the
    ``opentelemetry_metrics_exporter`` entry point group.
    NzLotlp_file_development metric exporter is experimental and not yet supported.opentelemetry_metrics_exporterzjNo exporter type specified in push metric exporter config. Supported types: console, otlp_http, otlp_grpc.rF   )	otlp_file_developmentr   r   itemsgetattradditional_propertiesnextiterr   )r?   rU   factoryvalueplugin_configs        r6   _create_push_metric_exporterr   T  s     #/ %
 
 	
 388:: " "gd++75>>!!! # 
"4(D(J(J(L(L#M#MNNmG @$GG 
 
"
 
 	
 	:  r8   PeriodicMetricReaderConfigr"   c                    t          | j                  }| j        | j        nt          }| j        | j        nt
          }t          |t          |          t          |                    S )zCreate a PeriodicExportingMetricReader from config.

    Passes explicit interval/timeout defaults to suppress env var reading.
    N)exporterexport_interval_millisexport_timeout_millis)r   r   interval_DEFAULT_EXPORT_INTERVAL_MILLISrt   _DEFAULT_EXPORT_TIMEOUT_MILLISr"   float)r?   r   r   rt   s       r6   _create_periodic_metric_readerr   r  sw     ,FO<<H ?& 	,  >% 	+ 
 )$X#Gnn   r8   MetricReaderConfigr   c                    | j         t          | j                   S | j        t          d          t          d          )z"Create a MetricReader from config.NzPull metric readers (e.g. Prometheus) are experimental and not yet supported by declarative config. Use the SDK API directly to configure pull readers.zLNo reader type specified in metric reader config. Supported types: periodic.)periodicr   pullr   )r?   s    r6   _create_metric_readerr     sS    "-fo>>>{ Y
 
 	
 	%  r8   r   ExemplarFilterConfigobjectc                    | t           j        k    rt                      S | t           j        k    rt	                      S | t           j        k    rt                      S t          d| d          )z5Create an SDK exemplar filter from config enum value.zUnknown exemplar filter value: z7. Supported values: always_on, always_off, trace_based.)r   	always_onr   
always_offr   trace_basedr   r   )r   s    r6   _create_exemplar_filterr     s     $...%'''$///&((($000')))
	@% 	@ 	@ 	@  r8   MeterProviderConfig | NoneresourceResource | Noner   c                H   t                      }| | j        t          | j                  }g }g }| _| j        D ]$}|                    t          |                     %| j        r,| j        D ]$}|                    t          |                     %t          ||||          S )a  Create an SDK MeterProvider from declarative config.

    Does NOT read OTEL_METRIC_EXPORT_INTERVAL, OTEL_METRICS_EXEMPLAR_FILTER,
    or any other env vars for values explicitly controlled by the config.
    Absent config values use OTel spec defaults, matching Java SDK behavior.

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

    Returns:
        A configured MeterProvider.
    N)r   metric_readersexemplar_filterviews)	r   r   r   readersappendr   r   rb   r   )r?   r   r   r   r   reader_configview_configs          r6   create_meter_providerr     s    & 788Of4@1&2HII"$GE#^ 	A 	AMNN0??@@@@< 	8%| 8 8\+667777'	   r8   Nonec                R    | dS t          j        t          | |                     dS )uT  Configure the global MeterProvider from declarative config.

    When config is None (meter_provider section absent from config file),
    the global is not set — matching Java/JS SDK behavior.

    Args:
        config: MeterProvider config from the parsed config file, or None.
        resource: Resource to attach to the provider.
    N)r   set_meter_providerr   )r?   r   s     r6   configure_meter_providerr     s0     ~4VXFFGGGGGr8   )r+   r,   r-   r.   )r+   r9   r-   r:   )r?   r@   r-   r	   )r?   rM   r-   r   )r?   rc   r-   r!   )r?   rj   r-   r!   )r?   r|   r-   r!   )r?   r   r-   r!   )r?   r   r-   r"   )r?   r   r-   r   )r   r   r-   r   )N)r?   r   r   r   r-   r   )r?   r   r   r   r-   r   )W
__future__r   loggingopentelemetryr   (opentelemetry.sdk._configuration._commonr   r   r   ,opentelemetry.sdk._configuration._exceptionsr   'opentelemetry.sdk._configuration.modelsr	   r@   r
   rc   r   r   r   r   r   r   MeterProviderConfigr   r   r   r|   r   rj   r   r   r   r   r   rM   opentelemetry.sdk.metricsr   r   r   r   r   r   r   r   r   r    opentelemetry.sdk.metrics.exportr    r!   r"   opentelemetry.sdk.metrics.viewr#   r$   r%   r&   r'   r(   opentelemetry.sdk.resourcesr)   	getLogger__name__r]   r   r   counterup_down_counter	histogramgaugeobservable_counterobservable_gaugeobservable_up_down_counterr*   __annotations__r7   r>   rL   rb   ri   r{   r   r   r   r   r   r   r   r   rF   r8   r6   <module>r      s   # " " " " " "  ! ! ! ! ! !         
 L K K K K K                        
                                                                         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 1 0 0 0 0 0
'
H
%
% #( !&  G"Mi&%'8#_-/F4     & & & &R   4" " " "J& & & &R   # # # #L       H 32.# #        <   2      $ !%& & & & &V !%H H H H H H Hr8   