
    ZjqQ              	          U d Z ddlZddlZddl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 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Z!edz  e"d<   	 ddl!Z#e#Z!n# e$$ r Y nw xY we Z%e	j&        e'e%f         Z( ej)        e*          Z+ej,        Z,ej-        Z-ej.        Z.ej/        Z/ej0        Z0ej1        Z1ej2        Z2ej3        Z3ej4        Z4ej5        Z5ej6        Z6ej7        Z7ej8        Z8ej9        Z9ej:        Z:ej;        Z;ej<        Z<ej=        Z=ej>        Z>ej?        Z@ejA        ZBejC        ZDejE        ZFejG        ZHejI        ZJejK        ZLejM        ZNejO        ZPejQ        ZRejS        ZTejU        ZVejW        ZXejY        ZZej[        Z\ej]        Z^ej_        Z`eja        Zaejb        Zbejc        Zcejd        Zdeje        Zeejf        Zfejg        Zgejh        Zheji        Ziejj        Zjejk        Zkejl        Zlejm        Zmejn        Znejo        Zoejp        Zpejq        Zqejr        Zrejs        Zsejt        Zteju        Zuejv        Zv G d d          Zw ewi           Zx ewevdesdetei          Zy G d dejz                  Z{ G d de{          Z| G d de{          Z} G d de{          Z~ G d de{          Zded         fdZ	 	 d$d ed         d!ewdz  d"eddfd#ZdS )%a  
This package implements `OpenTelemetry Resources
<https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk>`_:

    *A Resource is an immutable representation of the entity producing
    telemetry. For example, a process producing telemetry that is running in
    a container on Kubernetes has a Pod name, it is in a namespace and
    possibly is part of a Deployment which also has a name. All three of
    these attributes can be included in the Resource.*

Resource objects are created with `Resource.create`, which accepts attributes
(key-values). Resources should NOT be created via constructor except by `ResourceDetector`
instances which can't use `Resource.create` to avoid infinite loops. Working with
`Resource` objects should only be done via the Resource API methods. Resource
attributes can also be passed at process invocation in the
:envvar:`OTEL_RESOURCE_ATTRIBUTES` environment variable. You should register
your resource with the  `opentelemetry.sdk.trace.TracerProvider` by passing
them into their constructors. The `Resource` passed to a provider is available
to the exporter, which can send on this information as it sees fit.

.. code-block:: python

    trace.set_tracer_provider(
        TracerProvider(
            resource=Resource.create({
                "service.name": "shoppingcart",
                "service.instance.id": "instance-12",
            }),
        ),
    )
    print(trace.get_tracer_provider().resource.attributes)

    {'telemetry.sdk.language': 'python',
    'telemetry.sdk.name': 'opentelemetry',
    'telemetry.sdk.version': '0.13.dev0',
    'service.name': 'shoppingcart',
    'service.instance.id': 'instance-12'}

Note that the OpenTelemetry project documents certain `"standard attributes"
<https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md>`_
that have prescribed semantic meanings, for example ``service.name`` in the
above example.
    N)Sequence)dumps)environ)
ModuleType)cast)parse)BoundedAttributes)$OTEL_EXPERIMENTAL_RESOURCE_DETECTORSOTEL_RESOURCE_ATTRIBUTESOTEL_SERVICE_NAME)__version__)ResourceAttributes)AttributeValuepsutilc                      e Zd ZU dZeed<   eed<   ddededz  fdZe		 	 ddedz  dedz  dd fd	            Z
e	dd
            Zedefd            Zedefd            ZddZdedefdZdefdZddedz  defdZdS )ResourcezZA Resource is an immutable representation of the entity producing telemetry as Attributes._attributes_schema_urlN
attributes
schema_urlc                 F    t          |          | _        |d}|| _        d S )N)r    )r	   r   r   )selfr   r   s      a/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/sdk/resources/__init__.py__init__zResource.__init__   s.    ,
CCCJ%    returnc                    | si } t          t                      t                                        t	          | |                    }|j                            t          d          sld}t          t          dz  |j                            t          d                    }|r|d|z   z  }|                    t	          t          |i|                    }|S )a9  Creates a new `Resource` from attributes.

        `ResourceDetector` instances should not call this method.

        Args:
            attributes: Optional zero or more key-value pairs.
            schema_url: Optional URL pointing to the schema

        Returns:
            The newly-created Resource.
        Nunknown_service:)get_aggregated_resources_build_resource_detectors_DEFAULT_RESOURCEmerger   r   getSERVICE_NAMEr   strPROCESS_EXECUTABLE_NAME)r   r   resourcedefault_service_nameprocess_executable_names        r   createzResource.create   s    "  	J+%''):
 

%Z00
1
1 	 "&&|T:: 
	#4 &*d
#''(?FF' '# ' F$.E(EE$~~,(<=zJJ H r   c                      t           S N)_EMPTY_RESOURCE r   r   	get_emptyzResource.get_empty   s    r   c                     | j         S r.   )r   r   s    r   r   zResource.attributes       r   c                     | j         S r.   )r   r3   s    r   r   zResource.schema_url   r4   r   otherc                 n   t          | j                                                  }|                    |j                   | j        dk    r|j        }nS|j        dk    r| j        }n@| j        |j        k    r|j        }n(t
                              d| j        |j                   | S t          ||          S )a^  Merges this resource and an updating resource into a new `Resource`.

        If a key exists on both the old and updating resource, the value of the
        updating resource will override the old resource value.

        The updating resource's `schema_url` will be used only if the old
        `schema_url` is empty. Attempting to merge two resources with
        different, non-empty values for `schema_url` will result in an error
        and return the old resource.

        Args:
            other: The other resource to be merged.

        Returns:
            The newly-created Resource.
        r   zEFailed to merge resources: The two schemas %s and %s are incompatible)dictr   copyupdater   loggererrorr   )r   r6   merged_attributesr   s       r   r$   zResource.merge   s    " !116688  !1222?b  )JJ##JJ_ 000)JJLLW   
 K):666r   c                 p    t          |t                    sdS | j        |j        k    o| j        |j        k    S )NF)
isinstancer   r   r   )r   r6   s     r   __eq__zResource.__eq__   s?    %** 	5 11 6 E$55	
r   c                     t          t          | j                                        d           d| j                   S )NT)	sort_keys|)hashr   r   r9   r   r3   s    r   __hash__zResource.__hash__   sD    T%**,,===RR@PRR
 
 	
r      indentc                 X    t          t          | j                  | j        d|          S )N)r   r   )rG   )r   r8   r   r   )r   rG   s     r   to_jsonzResource.to_json  s;    "4?33".  
 
 
 	
r   r.   )NNr   r   )r6   r   r   r   )rF   )__name__
__module____qualname____doc__r	   __annotations__r'   
Attributesr   staticmethodr,   r1   propertyr   r   r$   objectboolr@   intrE   rI   r0   r   r   r   r      s        dd""""& &: &3: & & & & (,!%" "%"$J" 
" " " \"H    \  J       X   C       X !7 !7 !7 !7F
F 
t 
 
 
 

# 
 
 
 


 
cDj 
 
 
 
 
 
 
r   r   pythonopentelemetryc                   B    e Zd ZddeddfdZej        d	d            ZdS )
ResourceDetectorFraise_on_errorr   Nc                     || _         d S r.   )rZ   )r   rZ   s     r   r   zResourceDetector.__init__  s    ,r   r   c                     t                      )zdDon't call `Resource.create` here to avoid an infinite loop, instead instantiate `Resource` directly)NotImplementedErrorr3   s    r   detectzResourceDetector.detect  s     "###r   )FrJ   )rK   rL   rM   rT   r   abcabstractmethodr^   r0   r   r   rY   rY     s_        - -t - - - - - 	$ $ $ $ $ $r   rY   c                       e Zd ZddZdS )OTELResourceDetectorr   r   c                    t          j        t                    }i }|r|                    d          D ]}	 |                    dd          \  }}n3# t          $ r&}t
                              d||           Y d }~Id }~ww xY wt          j        |	                                          }|||	                                <   t          j        t                    }|r
||t          <   t          |          S )N,=   )maxsplitz0Invalid key value resource attribute pair %s: %s)r   r%   r   split
ValueErrorr;   warningr   unquotestripr   r&   r   )	r   env_resources_itemsenv_resource_mapitemkeyvalueexcvalue_url_decodedservice_names	            r   r^   zOTELResourceDetector.detect%  s   %k*BCC68 	B+11#66 B B!%C!!<!<JC!   NNJ  
 HHHH %*M%++--$@$@!0A --{#455 	:-9\*()))s   A
BA<<BNrJ   rK   rL   rM   r^   r0   r   r   rb   rb   #  s(        * * * * * *r   rb   c                       e Zd ZddZdS )ProcessResourceDetectorr   r   c                 |   d                     t          t          t          j        j        dk    r%t          j        j        st          j        d d         nt          j                            }t          j                    }t          j	        }t          j
                            |          }t          t          j                  }|r|d         nd}d                     |          }|}t          t          j        t           t          j        j        t&          |t(          |t*          |t,          |t.          |t0          |t2          |i	}	t5          t          d          rt          j                    |	t8          <   t:          7t:                                          }
|
                                }||	t@          <   tC          |	          S )N.final   r   r    getppid)"joinmapr'   sysversion_inforeleaselevelserialosgetpid
executablepathdirnamelist	orig_argvPROCESS_RUNTIME_DESCRIPTIONversionPROCESS_RUNTIME_NAMEimplementationnamePROCESS_RUNTIME_VERSIONPROCESS_PIDr(   PROCESS_EXECUTABLE_PATHPROCESS_COMMANDPROCESS_COMMAND_LINEPROCESS_COMMAND_ARGShasattrr}   PROCESS_PARENT_PIDr   ProcessusernamePROCESS_OWNERr   )r   _runtime_version_process_pid_process_executable_name_process_executable_path_process_argv_process_command_process_command_line_process_command_argsresource_infoprocessr   s               r   r^   zProcessResourceDetector.detect?  sq   88 '4??,3 @ $RaR(( ) 

 

 y{{#&> #%7??3K#L#L  S]++/<D=++" # 7 7 -' #"4"9#%5#%=#%=- "7 "7

 2y!! 	=02
M,-nn&&G''))H+3M-(&&&r   NrJ   ru   r0   r   r   rw   rw   =  s(        -' -' -' -' -' -'r   rw   c                       e Zd ZdZddZdS )OsResourceDetectorzxDetect os resources based on `Operating System conventions <https://opentelemetry.io/docs/specs/semconv/resource/os/>`_.r   r   c                    t          j                                                    }t          j                    }|dk    rt          j                    }n|dk    rd}t          j                    }t          t          |t          |i          S )a  Returns a resource with with ``os.type`` and ``os.version``.

        Python's platform library
        ~~~~~~~~~~~~~~~~~~~~~~~~~

        To grab this information, Python's ``platform`` does not return what a
        user might expect it to. Below is a breakdown of its return values in
        different operating systems.

        .. code-block:: python
            :caption: Linux

            >>> platform.system()
            'Linux'
            >>> platform.release()
            '6.5.0-35-generic'
            >>> platform.version()
            '#35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2'

        .. code-block:: python
            :caption: MacOS

            >>> platform.system()
            'Darwin'
            >>> platform.release()
            '23.0.0'
            >>> platform.version()
            'Darwin Kernel Version 23.0.0: Fri Sep 15 14:42:57 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8112'

        .. code-block:: python
            :caption: Windows

            >>> platform.system()
            'Windows'
            >>> platform.release()
            '2022Server'
            >>> platform.version()
            '10.0.20348'

        .. code-block:: python
            :caption: FreeBSD

            >>> platform.system()
            'FreeBSD'
            >>> platform.release()
            '14.1-RELEASE'
            >>> platform.version()
            'FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC'

        .. code-block:: python
            :caption: Solaris

            >>> platform.system()
            'SunOS'
            >>> platform.release()
            '5.11'
            >>> platform.version()
            '11.4.0.15.0'

        windowssunossolaris)platformsystemlowerreleaser   r   OS_TYPE
OS_VERSION)r   os_type
os_versions      r   r^   zOsResourceDetector.detectr  s    | /##))++%''
 i!)++JJG!)++JJ
 
 	
r   NrJ   rK   rL   rM   rN   r^   r0   r   r   r   r   o  s:         C  CN
 N
 N
 N
 N
 N
r   r   c                       e Zd ZdZddZdS )_HostResourceDetectorzT
    The HostResourceDetector detects the hostname and architecture attributes.
    r   r   c                     t          t          t          j                    t          t          j                    i          S r.   )r   	HOST_NAMEsocketgethostname	HOST_ARCHr   machiner3   s    r   r^   z_HostResourceDetector.detect  s5    6-//8+--
 
 	
r   NrJ   r   r0   r   r   r   r     s2         
 
 
 
 
 
r   r   r   c                     t          t                              d t          j        t
          d                              d          D             dgz                       } | dgk    rt                      gS ddlm	} d| v rwt          d  |d	
          j        D                       }t          |t          |           z
            }|                     d          }| d|         |z   | |dz   d         z   } g }| D ]}	 |                     t          t!           |d	|                                                                                     X# t$          $ r t&                              d|           Y w xY w|S )a  Returns the ordered list of resource detectors to use for Resource.create.

    Fast path: if no extra detectors are configured, returns only
    OTELResourceDetector without scanning entry_points.

    "otel" (OTELResourceDetector) defaults to last position so that
    OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME take highest merge priority,
    but an explicit position in OTEL_EXPERIMENTAL_RESOURCE_DETECTORS is respected.
    c                 ^    g | ]*}|                                 |                                 +S r0   )rl   .0r   s     r   
<listcomp>z-_build_resource_detectors.<locals>.<listcomp>  s@        ::<<

  r   r   rd   otelr   )entry_points*c              3   &   K   | ]}|d k    |V  dS )r   Nr0   r   s     r   	<genexpr>z,_build_resource_detectors.<locals>.<genexpr>  s8       
 
 v~~	  ~~~
 
r   opentelemetry_resource_detector)groupNrf   )r   r   z/Failed to load resource detector '%s', skipping)r   r8   fromkeysr   r%   r
   rh   rb   &opentelemetry.util._importlib_metadatar   setnamessortedindexappendnextiterload	Exceptionr;   	exception)detector_namesr   
registered	expansionidx	detectorsr   s          r   r"   r"     s    !% #K8" %**	   h		
 		
! !N &!!$&&''      n 
 
$7  	
 
 
 
 

 :N(;(;;<<	""3''4C4 9,~cAgii/HH 	 )+I  	$"C!%     $&& 	 	 	 	  	 	 	A    	
 s   ?AE%E<;E<   r   initial_resourcetimeoutc                   
 |pt                                           }t          j                            d          5 

fd| D             }t          |          D ]\  }}| |         }t          }	 |                    |          }n}# t          j        j        $ r/}	|j	        r|	t                              d||           Y d}	~	n?d}	~	wt          $ r/}	|j	        r|	t                              d|	|           Y d}	~	nd}	~	ww xY w|                    |          }# |                    |          }w xY w	 ddd           n# 1 swxY w Y   |S )a'  Retrieves resources from detectors in the order that they were passed

    :param detectors: List of resources in order of priority
    :param initial_resource: Static resource. This has highest priority
    :param timeout: Number of seconds to wait for each detector to return
    :return:
    rF   )max_workersc                 D    g | ]}                     |j                  S r0   )submitr^   )r   detectorexecutors     r   r   z,get_aggregated_resources.<locals>.<listcomp>#  s'    NNN8??8?33NNNr   )r   z1Detector %s took longer than %s seconds, skippingNz%Exception %s in detector %s, ignoring)r   r,   
concurrentfuturesThreadPoolExecutor	enumerater/   resultTimeoutErrorrZ   r;   rj   r   r$   )r   r   r   detectors_merged_resourcer   detector_indfuturer   detected_resourceexr   s             @r   r!   r!     s    !1 EHOO4E4E			.	.1	.	=	= NNNNINNN$-g$6$6 	 	 L& .H*9$*MM'M$B$B!!%2   * HG           * H;R        -F,K,K%- -)),E,K,K%- -)    +	              6 %$s_   2E0BDD%C DD%C<7D<DDED11EEE)Nr   )rN   r_   concurrent.futuresr   loggingr   r   r   r   typingcollections.abcr   jsonr   r   typesr   r   urllibr   opentelemetry.attributesr	   'opentelemetry.sdk.environment_variablesr
   r   r   opentelemetry.sdk.versionr   _OPENTELEMETRY_SDK_VERSIONopentelemetry.semconv.resourcer   opentelemetry.util.typesr   r   rO   psutil_moduleImportError
LabelValueMappingr'   rP   	getLoggerrK   r;   CLOUD_PROVIDERCLOUD_ACCOUNT_IDCLOUD_REGIONCLOUD_AVAILABILITY_ZONECONTAINER_NAMECONTAINER_IDCONTAINER_IMAGE_NAMECONTAINER_IMAGE_TAGDEPLOYMENT_ENVIRONMENT	FAAS_NAMEFAAS_IDFAAS_VERSIONFAAS_INSTANCEr   r   	HOST_TYPEHOST_IMAGE_NAMEHOST_IMAGE_IDHOST_IMAGE_VERSIONK8S_CLUSTER_NAMEKUBERNETES_CLUSTER_NAMEK8S_NAMESPACE_NAMEKUBERNETES_NAMESPACE_NAMEK8S_POD_UIDKUBERNETES_POD_UIDK8S_POD_NAMEKUBERNETES_POD_NAMEK8S_CONTAINER_NAMEKUBERNETES_CONTAINER_NAMEK8S_REPLICASET_UIDKUBERNETES_REPLICA_SET_UIDK8S_REPLICASET_NAMEKUBERNETES_REPLICA_SET_NAMEK8S_DEPLOYMENT_UIDKUBERNETES_DEPLOYMENT_UIDK8S_DEPLOYMENT_NAMEKUBERNETES_DEPLOYMENT_NAMEK8S_STATEFULSET_UIDKUBERNETES_STATEFUL_SET_UIDK8S_STATEFULSET_NAMEKUBERNETES_STATEFUL_SET_NAMEK8S_DAEMONSET_UIDKUBERNETES_DAEMON_SET_UIDK8S_DAEMONSET_NAMEKUBERNETES_DAEMON_SET_NAMEK8S_JOB_UIDKUBERNETES_JOB_UIDK8S_JOB_NAMEKUBERNETES_JOB_NAMEK8S_CRONJOB_UIDKUBERNETES_CRON_JOB_UIDK8S_CRONJOB_NAMEKUBERNETES_CRON_JOB_NAMEOS_DESCRIPTIONr   r   r   r   r(   r   r   r   r   r   r   r   r   r&   SERVICE_NAMESPACESERVICE_INSTANCE_IDSERVICE_VERSIONTELEMETRY_SDK_NAMETELEMETRY_SDK_VERSIONTELEMETRY_AUTO_VERSIONTELEMETRY_SDK_LANGUAGEr   r/   r#   ABCrY   rb   rw   r   r   r   r"   rU   r!   r0   r   r   <module>r;     s  * * *^ 


      				   



  $ $ $ $ $ $                               6 6 6 6 6 6         
      > = = = = = 3 3 3 3 3 3 
T      	""""FF 	 	 	D	 
^CO,
		8	$	$#2%6 !.,D #2!.)> (< +B (	

$!."0(	(	(	$4"0': ,= .A '3 (5 .A /B 0D .A /C 0D 1F .@ /B '3 (5 ,< -> #2

$*
 ,': ,D ,D $4)> )> "0)> ,D 0L !.&8 (< $4': *@ +B +B t
 t
 t
 t
 t
 t
 t
 t
n (2,,HO9  $ $ $ $ $sw $ $ $* * * * *+ * * *4/' /' /' /' /'. /' /' /'dQ
 Q
 Q
 Q
 Q
) Q
 Q
 Q
h
 
 
 
 
, 
 
 
@4(:#; @ @ @ @J )-)% )%*+)%o)% )% 	)% )% )% )% )% )%s   5A< <BB