
    tinN              	          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mZmZ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mZ ddl m!Z! dZ"ee         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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j@        ZAejB        ZCejD        ZEejF        ZGejH        ZIejJ        ZKejL        ZMejN        ZOejP        ZQejR        ZSejT        ZUejV        ZWejX        ZYejZ        Z[ej\        Z]ej^        Z_ej`        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        Zvejw        Zw ed          Zxe(e#d<    G d d          Zy eyi           Zz eyewdetdeuexi          Z{ G d dej|                  Z} G d de}          Z~ G d de}          Z G d de}          Z G d de}          Z	 	 d$de	j        d         d e	j        ey         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)dumps)environ)
ModuleType)ListOptionalSetcast)parse)BoundedAttributes)$OTEL_EXPERIMENTAL_RESOURCE_DETECTORSOTEL_RESOURCE_ATTRIBUTESOTEL_SERVICE_NAME)ResourceAttributes)entry_pointsversion)AttributeValuepsutilzopentelemetry-sdk_OPENTELEMETRY_SDK_VERSIONc                   :   e Zd ZU dZeed<   eed<   	 ddedej	        e         fdZ
e	 	 ddej	        e         dej	        e         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	e         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      W/var/www/icac/venv/lib/python3.11/site-packages/opentelemetry/sdk/resources/__init__.py__init__zResource.__init__   s0     -
CCCJ%    returnc                    | si } dh                     d t          j        t          d                              d          D                       }g }d|v rt          d          j        }|D ]}	 |                     t          t          t          d|
                                                                                                                     n# t          $ r t                              d	|           Y w xY wt          |t                                         t%          | |                    }|j                            t(          d
          std}t+          t,          t.                   |j                            t0          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.
        otelc                 :    h | ]}||                                 S  )strip).0#otel_experimental_resource_detectors     r   	<setcomp>z"Resource.create.<locals>.<setcomp>   s<       7 7399;;  r    r   ,*opentelemetry_resource_detector)group)r-   namez/Failed to load resource detector '%s', skippingNunknown_service:)unionr   getr   splitr   namesappendnextiterr&   load	Exceptionlogger	exceptionget_aggregated_resources_DEFAULT_RESOURCEmerger   r   SERVICE_NAMEr	   r   strPROCESS_EXECUTABLE_NAME)r   r   $otel_experimental_resource_detectorsresource_detectorsresource_detectorresourcedefault_service_nameprocess_executable_names           r   createzResource.create   s)   "  	J:@ ;B;8"< <%**	  :
 :
, 686663?74 4 4 1 "F 	 	"))D(&G%6%<%<%>%>     dff 	 	 	 	      E%    , 1
 

%Z00
1
1 	 "&&|T:: 
	#4 &*#''(?FF' '# ' F$.E(EE$~~,(<=zJJ H s   0A*C%DDc                      t           S N)_EMPTY_RESOURCEr%   r    r   	get_emptyzResource.get_empty   s    r    c                     | j         S rJ   )r   r   s    r   r   zResource.attributes       r    c                     | j         S rJ   )r   rN   s    r   r   zResource.schema_url  rO   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   r:   errorr   )r   rQ   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   rQ   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   rT   r   rN   s    r   __hash__zResource.__hash__1  sD    T%**,,===RR@PRR
 
 	
r       indentc                 X    t          t          | j                  | j        d|          S )N)r   r   )ra   )r   rS   r   r   )r   ra   s     r   to_jsonzResource.to_json6  s;    "4?33".  
 
 
 	
r    rJ   )NNr!   r   )rQ   r   r!   r   )r`   )__name__
__module____qualname____doc__r   __annotations__r@   
Attributestypingr   r   staticmethodrH   rL   propertyr   r   r>   objectboolrZ   intr_   rc   r%   r    r   r   r      s        dd"""" JN& &$&28/#2F& & & & 26+/E EOJ/EOC(E 
E E E \EN    \  J       X   C       X !7 !7 !7 !7F
F 
t 
 
 
 

# 
 
 
 


 
hsm 
C 
 
 
 
 
 
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 rJ   )ru   )r   ru   s     r   r   zResourceDetector.__init__K  s    ,r    r   c                     t                      )zdDon't call `Resource.create` here to avoid an infinite loop, instead instantiate `Resource` directly)NotImplementedErrorrN   s    r   detectzResourceDetector.detectN  s     "###r    )Frd   )re   rf   rg   ro   r   abcabstractmethodry   r%   r    r   rt   rt   J  s_        - -t - - - - - 	$ $ $ $ $ $r    rt   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 )Nr*   =   )maxsplitz0Invalid key value resource attribute pair %s: %s)r   r2   r   r3   
ValueErrorr:   warningr
   unquoter&   r   r?   r   )	r   env_resources_itemsenv_resource_mapitemkeyvalueexcvalue_url_decodedservice_names	            r   ry   zOTELResourceDetector.detectV  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Nrd   re   rf   rg   ry   r%   r    r   r}   r}   T  s(        * * * * * *r    r}   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          j        d         }d                     t          j                  }t          j        }t          t          j        t          t          j        j        t$          |t&          |t(          |t*          |t,          |t.          |t0          |i	}t3          t          d          rt          j                    |t6          <   t8          7t8                                          }	|	                                }
|
|t>          <   tA          |          S )N.final   r    getppid)!joinmapr@   sysversion_inforeleaselevelserialosgetpid
executablepathdirnameargvPROCESS_RUNTIME_DESCRIPTIONr   PROCESS_RUNTIME_NAMEimplementationr.   PROCESS_RUNTIME_VERSIONPROCESS_PIDrA   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_command_process_command_line_process_command_argsresource_infoprocessr   s              r   ry   zProcessResourceDetector.detectp  s[   88 '4??,3 @ $RaR(( ) 

 

 y{{#&> #%7??3K#L#L 8A; # 2 2 #' #"4"9#%5#%=#%=- "7 "7

 2y!! 	=02
M,-nn&&G''))H+3M-(&&&r    Nrd   r   r%   r    r   r   r   n  s(        &' &' &' &' &' &'r    r   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   ry   zOsResourceDetector.detect  s    | /##))++%''
 i!)++JJG!)++JJ
 
 	
r    Nrd   re   rf   rg   rh   ry   r%   r    r   r   r     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 rJ   )r   	HOST_NAMEsocketgethostname	HOST_ARCHr   machinerN   s    r   ry   z_HostResourceDetector.detect  s5    6-//8+--
 
 	
r    Nrd   r   r%   r    r   r   r     s2         
 
 
 
 
 
r    r      	detectorsinitial_resourcetimeoutr!   c                   
 |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:
    r`   )max_workersc                 D    g | ]}                     |j                  S r%   )submitry   )r'   detectorexecutors     r   
<listcomp>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   rH   
concurrentfuturesThreadPoolExecutor	enumeraterK   resultTimeoutErrorru   r:   r   r9   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   )rh   rz   concurrent.futuresr   loggingr   r   r   r   rk   jsonr   r   typesr   r   r   r   r	   urllibr
   opentelemetry.attributesr   'opentelemetry.sdk.environment_variablesr   r   r   opentelemetry.semconv.resourcer   &opentelemetry.util._importlib_metadatar   r   opentelemetry.util.typesr   r   ri   psutil_moduleImportError
LabelValueMappingr@   rj   	getLoggerre   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   rA   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   rK   r=   ABCrt   r}   r   r   r   rp   r<   r%   r    r   <module>r1     s  * * *^ 


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



                    , , , , , , , , , , , ,       6 6 6 6 6 6         
 > = = = = =        4 3 3 3 3 3# # # #	""""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 ")'*=">"> C > > >Y
 Y
 Y
 Y
 Y
 Y
 Y
 Y
x (2,,HO9  $ $ $ $ $sw $ $ $* * * * *+ * * *4(' (' (' (' ('. (' (' ('VQ
 Q
 Q
 Q
 Q
) Q
 Q
 Q
h
 
 
 
 
, 
 
 
  37)% )%{-.)%oh/)% )% 	)% )% )% )% )% )%s   :B B	B	