
    Zjx                       U d dl mZ d dlZd dlZd dlZd dlZd dl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 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  ej        e           Z!d1dZ"d2dZ#ej$        e%ej&        e&ej'        e(ej)        e"ej*         e#e%          ej+         e#e&          ej,         e#e(          ej-         e#e"          iZ.d3dZ/d4dZ0d5dZ1d6d!Z2e2d" d# d$Z3d%e4d&<   d7d,Z5d8d0Z6dS )9    )annotationsN)Callable)Any)parse)load_entry_point)AttributeNameValueAttributeTypeExperimentalResourceDetectorIncludeExclude)Resource)_DEFAULT_RESOURCEOTEL_SERVICE_NAMESERVICE_INSTANCE_IDSERVICE_NAMEProcessResourceDetectorr   _HostResourceDetector)AttributeValuevalueobjectreturnboolc                v    t          | t                    r|                                 dvS t          |           S )N)false0 )
isinstancestrlowerr   )r   s    g/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/sdk/_configuration/_resource.py_coerce_boolr    %   s4    % 7{{}}$666;;    coercer   c                      fdS )Nc                     fd| D             S )Nc                &    g | ]} |          S  r&   ).0itemr"   s     r   
<listcomp>z,_array.<locals>.<lambda>.<locals>.<listcomp>,   s!    9994&&,,999r!   r&   )r   r"   s    r   <lambda>z_array.<locals>.<lambda>,   s    99995999 r!   r&   )r"   s   `r   _arrayr+   +   s    99999r!   attrr   c                r    t                               | j                  }| || j                  n| j        S )zLCoerce an attribute value to the correct Python type based on AttributeType.)
_COERCIONSgettyper   )r,   r"   s     r   _coerce_attribute_valuer1   <   s3    ^^DI&&F!'!366$*Cr!   attributes_listr   dict[str, str]c                R   i }|                      d          D ]}|                                }|sd|vrt                              d|           9|                     dd          \  }}t	          j        |                                          ||                                <   |S )zParse a comma-separated key=value string into a dict.

    Format is the same as OTEL_RESOURCE_ATTRIBUTES: key=value,key=value
    Values are always strings (no type coercion).
    ,=z6Invalid resource attribute pair in attributes_list: %s   )maxsplit)splitstrip_loggerwarningr   unquote)r2   resultr(   keyr   s        r   _parse_attributes_listr@   B   s      F%%c** ; ;zz|| 	d??OOH   ZZaZ00
U#mEKKMM::syy{{Mr!   configResourceConfig | Noner   c                J   t          j        t          t          di                    }| |S i }| j        r'|                    t          | j                             | j        r!| j        D ]}t          |          ||j	        <   | j
        }|}| j        rki }| j        j        r| j        j        D ]}t          ||           t          || j        j                  }|r"|                    t          |                    }t          ||          }	|                    |	          S )aZ  Create an SDK Resource from declarative config.

    Does NOT read OTEL_RESOURCE_ATTRIBUTES. Resource detectors are only run
    when explicitly listed under detection_development.detectors in the config.
    Starts from SDK telemetry defaults (telemetry.sdk.*), merges any detected
    attributes, then merges explicit config attributes on top (highest priority).

    Args:
        config: Resource config from the parsed config file, or None.

    Returns:
        A Resource with SDK defaults, optional detector attributes, and any
        config-specified attributes merged in priority order.
    unknown_service)r   merger   r   r2   updater@   
attributesr1   name
schema_urldetection_development	detectors_run_detectors_filter_attributes)
rA   baseconfig_attrsr,   rI   r>   detected_attrsdetector_configfilteredconfig_resources
             r   create_resourcerT   X   sL   " "8\;L,M#N#NOOD~ ')L L263IJJKKK D% 	D 	DD&=d&C&CL##"J
 F# 
6,.'1 	@#)#?#I @ @????%F8C
 
  	6\\(8"4"455F|Z88O<<(((r!   _configr   dict[str, AttributeValue]c                    t           t          t          j                              i}t          j                            t                    x}r
||t          <   |S )zDService detector: generates instance ID and reads OTEL_SERVICE_NAME.)	r   r   uuiduuid4osenvironr/   r   r   )rU   attrsservice_names      r   _detect_servicer^      sK     	S..(E z~~&7888| +*lLr!   c                f    t          t                                                      j                  S N)dictr   detectrG   _s    r   r*   r*      s$    d02299;;FGG r!   c                f    t          t                                                      j                  S r`   )ra   r   rb   rG   rc   s    r   r*   r*      s$    577>>@@KLL r!   )servicehostprocessz5dict[str, Callable[[Any], dict[str, AttributeValue]]]_RESOURCE_DETECTOR_REGISTRYrQ   r
   rP   dict[str, object]Nonec                6   t          j        |           D ]}t          | |j        d          }||j        t          v r.|                    t	          |j                 |                     Wt          d|j                  }|                     |di |pi                                 j                   | j	        
                                D ]I\  }}t          d|          }|                     |di |pi                                 j                   JdS )u  Run detectors present in a single detector config entry.

    Known detectors (service, host, process) are handled directly via
    _RESOURCE_DETECTOR_REGISTRY. All other detectors — including known
    schema fields like container that require contrib packages, and
    unknown plugin detectors captured in additional_properties — are
    loaded via the ``opentelemetry_resource_detector`` entry point group.

    The detected_attrs dict is updated in-place; later detectors overwrite
    earlier ones for the same key.
    Nopentelemetry_resource_detectorr&   )dataclassesfieldsgetattrrH   ri   rF   r   rb   rG   additional_propertiesitems)rQ   rP   rH   r   clsplugin_configs         r   rL   rL      sH    "?33 L LD99=9333!!+DI6u==    #149 C !!##"6"6""6"6"="="?"?"JKKKK.DJJLL P Pm@$GGcc::]%8b::AACCNOOOOP Pr!   r\   filter_configIncludeExclude | Nonec                    || S |j         }|j        }|s|s| S i }|                                 D ]F\  }|rt          fd|D                       s#|rt          fd|D                       rA||<   G|S )uy  Filter detected attribute keys using include/exclude glob patterns.

    Mirrors other SDK IncludeExcludePredicate.createPatternMatching behaviour:
    - No filter config (attributes absent) → include all detected attributes.
    - included patterns are checked first; excluded patterns are applied after.
    - An empty included list is treated as "include everything".
    Nc              3  B   K   | ]}t          j         |          V  d S r`   fnmatchr'   patr?   s     r   	<genexpr>z%_filter_attributes.<locals>.<genexpr>   s/      NNcS 9 9NNNNNNr!   c              3  B   K   | ]}t          j         |          V  d S r`   ry   r{   s     r   r}   z%_filter_attributes.<locals>.<genexpr>   s/      JJ#GOC55JJJJJJr!   )includedexcludedrr   any)r\   ru   r   r   r>   r   r?   s         @r   rM   rM      s     %H%H H  "Fkkmm  
U 	CNNNNXNNNNN 	 	JJJJJJJJJ 	sMr!   )r   r   r   r   )r"   r   r   r   )r,   r   r   r   )r2   r   r   r3   )rA   rB   r   r   )rU   r   r   rV   )rQ   r
   rP   rj   r   rk   )r\   rj   ru   rv   r   rj   )7
__future__r   rn   rz   loggingrZ   rX   collections.abcr   typingr   urllibr   (opentelemetry.sdk._configuration._commonr   'opentelemetry.sdk._configuration.modelsr   r	   r
   r   r   ResourceConfigopentelemetry.sdk.resourcesr   r   r   r   r   r   opentelemetry.util.typesr   	getLogger__name__r;   r    r+   stringr   intdoublefloatr   string_array	int_arraydouble_array
bool_arrayr.   r1   r@   rT   r^   ri   __annotations__rL   rM   r&   r!   r   <module>r      s   # " " " " " "       				  $ $ $ $ $ $             E E E E E E            O N N N N N                  4 3 3 3 3 3
'
H
%
%   : : : : #s%sVVC[[uff\22	
D D D D   ,2) 2) 2) 2)j    GGLL      P P P PD     r!   