
    3iM              	          % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SSKJr  SSK	JrJrJr  SSKJr  SSKJr  SS	KJrJrJr  SS
KJr  SSKJrJr  SSKJ r   Sr!\\   \"S'    SSK!r#\#r!\ r%\	RL                  \'\%4   r(\RR                  " \*5      r+\RX                  r,\RZ                  r-\R\                  r.\R^                  r/\R`                  r0\Rb                  r1\Rd                  r2\Rf                  r3\Rh                  r4\Rj                  r5\Rl                  r6\Rn                  r7\Rp                  r8\Rr                  r9\Rt                  r:\Rv                  r;\Rx                  r<\Rz                  r=\R|                  r>\R~                  r@\R                  rB\R                  rD\R                  rF\R                  rH\R                  rJ\R                  rL\R                  rN\R                  rP\R                  rR\R                  rT\R                  rV\R                  rX\R                  rZ\R                  r\\R                  r^\R                  r`\R                  ra\R                  rb\R                  rc\R                  rd\R                  re\R                  rf\R                  rg\R                  rh\R                  ri\R                  rj\R                  rk\R                  rl\R                  rm\R                  rn\R                  ro\R                  rp\R                  rq\R                  rr\R                  rs\R                  rt\R                  ru\R                  rv\" S5      rw\'\"S'    " S S5      rx\x" 0 5      ry\x" \vS\sS\t\w05      rz " S S\R                  5      r| " S S\|5      r} " S S\|5      r~ " S S\|5      r " S S\|5      r  S#S\	R                  S   S\	R                   \x   S \S!S4S" jjrg! \$ a     GNf = f)$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cast)parse)BoundedAttributes)$OTEL_EXPERIMENTAL_RESOURCE_DETECTORSOTEL_RESOURCE_ATTRIBUTESOTEL_SERVICE_NAME)ResourceAttributes)entry_pointsversion)AttributeValuepsutilzopentelemetry-sdk_OPENTELEMETRY_SDK_VERSIONc                   F   \ rS rSr% Sr\\S'   \\S'    SS\S\	R                  \   4S jjr\  SS\	R                  \   S\	R                  \   S	S 4S
 jj5       r\SS j5       r\S	\4S j5       r\S	\4S j5       rSS jrS\S	\4S jrS	\4S jrSS\
\   S	\4S jjrSrg)Resource   zZA Resource is an immutable representation of the entity producing telemetry as Attributes._attributes_schema_urlN
attributes
schema_urlc                 6    [        US9U l        Uc  SnX l        g )N)r    )r
   r   r   )selfr   r   s      ^/home/james-whalen/.local/lib/python3.13/site-packages/opentelemetry/sdk/resources/__init__.py__init__Resource.__init__   s"     -
CJ%    returnc                 N   U (       d  0 n S1R                  [        R                  " [        S5      R	                  S5       Vs1 s H  nU(       d  M  UR                  5       iM     sn5      n/ nU HP  n UR                  [        [        [        SUR                  5       S95      5      R                  5       " 5       5        MR     [        U[        5      R!                  [#        X5      5      nUR$                  R                  [&        S5      (       dg  Sn[)        [*        [,           UR$                  R                  [.        S5      5      nU(       a  US	U-   -  nUR!                  [#        [&        U0U5      5      nU$ s  snf ! [         a    [        R                  SU5         GM3  f = f)
a  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.
otelr   ,opentelemetry_resource_detector)groupnamez/Failed to load resource detector '%s', skippingNunknown_service:)unionr   getr   splitstrip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_detector$otel_experimental_resource_detectorsresource_detectorsresource_detectorresourcedefault_service_nameprocess_executable_names	            r   createResource.create   s   " J06x~~ <C;;8"<%*<<7 7	 <399;<0
, 68 "F"))(&G%6%<%<%> df 	 "F$ , 1

%0
1 	 ""&&|T::#4 &*##''(?F'# '$.E(EE$~~,(<=zJH [0    E% s   E:E:4AE?? F$#F$c                      [         $ N)_EMPTY_RESOURCE r!   r   	get_emptyResource.get_empty   s    r!   c                     U R                   $ rF   )r   r   s    r   r   Resource.attributes       r!   c                     U R                   $ rF   )r   rL   s    r   r   Resource.schema_url   rN   r!   otherc                    [        U R                  5      R                  5       nUR                  UR                  5        U R                  S:X  a  UR                  nOqUR                  S:X  a  U R                  nOTU R                  UR                  :X  a  UR                  nO-[
        R                  SU R                  UR                  5        U $ [        X#5      $ )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   r4   errorr   )r   rQ   merged_attributesr   s       r   r8   Resource.merge  s    " !1668  !1!12??b ))J#J__ 0 00))JLLW  
 K)66r!   c                     [        U[        5      (       d  gU R                  UR                  :H  =(       a    U R                  UR                  :H  $ )NF)
isinstancer   r   r   )r   rQ   s     r   __eq__Resource.__eq__%  sD    %** 1 11 6  E$5$55	
r!   c                 v    [        [        U R                  R                  5       SS9 SU R                   35      $ )NT)	sort_keys|)hashr   r   rT   r   rL   s    r   __hash__Resource.__hash__-  s;    T%%**,=>a@P@P?QR
 	
r!   indentc                 V    [        [        U R                  5      U R                  S.US9$ )N)r   r   )rc   )r   rS   r   r   )r   rc   s     r   to_jsonResource.to_json2  s.    "4??3".. 
 	
r!   )r   r   rF   )NNr"   r   )rQ   r   r"   r   )   )__name__
__module____qualname____firstlineno____doc__r
   __annotations__r:   
Attributestypingr   r   staticmethodrC   rI   propertyr   r   r8   objectboolr[   intra   re   __static_attributes__rH   r!   r   r   r      s   d"" JN&$&28//#2F& 26+/AOOJ/AOOC(A 
A AF    J      C    !7F
F 
t 

# 


hsm 
C 
 
r!   r   pythonopentelemetryc                   R    \ rS rSrSS\SS4S jjr\R                  S	S j5       rSr	g)
ResourceDetectoriF  raise_on_errorr"   Nc                     Xl         g rF   r{   )r   r{   s     r   r   ResourceDetector.__init__G  s    ,r!   c                     [        5       e)zdDon't call `Resource.create` here to avoid an infinite loop, instead instantiate `Resource` directly)NotImplementedErrorrL   s    r   detectResourceDetector.detectJ  s     "##r!   r}   )Frg   )
ri   rj   rk   rl   rt   r   abcabstractmethodr   rv   rH   r!   r   rz   rz   F  s/    -t - - 	$ $r!   rz   c                       \ rS rSrSS jrSrg)OTELResourceDetectoriP  c                    [         R                  " [        5      n0 nU(       aa  UR                  S5       HL  n UR                  SSS9u  pE[        R                  " UR                  5       5      nXrUR                  5       '   MN     [         R                  " [        5      nU(       a  X[        '   [        U5      $ ! [         a"  n[
        R                  SUU5         S nAM  S nAff = f)Nr%   =   )maxsplitz0Invalid key value resource attribute pair %s: %s)r   r,   r   r-   
ValueErrorr4   warningr	   unquoter.   r   r9   r   )	r   env_resources_itemsenv_resource_mapitemkeyvalueexcvalue_url_decodedservice_names	            r   r   OTELResourceDetector.detectR  s    %kk*BC68+11#6!%C!!<JC %*MM%++-$@!0A- 7 {{#45-9\*()) " NNJ
 s   B99
C%C  C%rH   Nrg   ri   rj   rk   rl   r   rv   rH   r!   r   r   r   P  s    *r!   r   c                       \ rS rSrSS jrSrg)ProcessResourceDetectorij  c                    SR                  [        [        [        R                  R
                  S:X  a2  [        R                  R                  (       d  [        R                  S S O[        R                  5      5      n[        R                  " 5       n[        R                  n[        R                  R                  U5      n[        R                  S   nSR                  [        R                  5      n[        R                  n[        [        R                  [        [        R                   R"                  [$        U[&        U[(        U[*        U[,        U[.        U[0        U0	n[3        [        S5      (       a  [        R4                  " 5       U[6        '   [8        b,  [8        R;                  5       n	U	R=                  5       n
X[>        '   [A        U5      $ )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_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_command_process_command_line_process_command_argsresource_infoprocessr   s              r   r   ProcessResourceDetector.detectl  sQ   88 ''44?,,33 $$Ra( ))

 yy{#&>> #%77??3K#L 88A; # 2 #' #"4"4"9"9#%5#%=#%=- "7 "7

 2y!!02

M,-nn&G'')H+3-(&&r!   rH   Nrg   r   rH   r!   r   r   r   j  s    &'r!   r   c                   "    \ rS rSrSrSS jrSrg)OsResourceDetectori  zxDetect os resources based on `Operating System conventions <https://opentelemetry.io/docs/specs/semconv/resource/os/>`_.c                    [         R                  " 5       R                  5       n[         R                  " 5       nUS:X  a  [         R                  " 5       nOUS:X  a  Sn[         R                  " 5       n[        [        U[        U05      $ )aC  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   OsResourceDetector.detect  sw    | //#))+%%'
 i!))+JG!))+JJ
 	
r!   rH   Nrg   ri   rj   rk   rl   rm   r   rv   rH   r!   r   r   r     s     CN
r!   r   c                   "    \ rS rSrSrSS jrSrg)_HostResourceDetectori  zL
The HostResourceDetector detects the hostname and architecture attributes.
c                 |    [        [        [        R                  " 5       [        [
        R                  " 5       05      $ rF   )r   	HOST_NAMEsocketgethostname	HOST_ARCHr   machinerL   s    r   r   _HostResourceDetector.detect  s0    6--/8++-
 	
r!   rH   Nrg   r   rH   r!   r   r   r     s    
r!   r   	detectorsinitial_resourcetimeoutr"   c                    U=(       d    [         R                  5       n[        R                  R	                  SS9 nU  Vs/ s H  oTR                  UR                  5      PM     nn[        U5       H0  u  pxX   n[        n	 UR                  US9n	UR                  U	5      nM2     SSS5        U$ s  snf ! [        R                  R                   a4  n
UR                  (       a  U
e[        R                  SUU5         Sn
A
NqSn
A
f[         a3  n
UR                  (       a  U
e[        R                  SX5         Sn
A
NSn
A
ff = f! UR                  U	5      nf = f! , (       d  f       U$ = f)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:
rh   )max_workers)r   z1Detector %s took longer than %s seconds, skippingNz%Exception %s in detector %s, ignoring)r   rC   
concurrentfuturesThreadPoolExecutorsubmitr   	enumeraterG   resultTimeoutErrorr{   r4   r   r3   r8   )r   r   r   detectors_merged_resourceexecutordetectorr   detector_indfuturedetected_resourceexs              r   r6   r6     sL    !1 EHOO4E				.	.1	.	=DMNI??8??3IN$-g$6 L .H*9$*MM'M$B!" -F,K,K%-)+ %7 
>6 %$5 O %%22 **HG   **H;R  -F,K,K%-)/ 
>	=6 %$se   E $B/$EB4E/E4E*D<EE)D<7E<EEEE
E))N   )rm   r   concurrent.futuresr   loggingr   r   r   r   rp   jsonr   r   typesr   r   r   r   urllibr	   opentelemetry.attributesr
   'opentelemetry.sdk.environment_variablesr   r   r   opentelemetry.semconv.resourcer   &opentelemetry.util._importlib_metadatar   r   opentelemetry.util.typesr   r   rn   psutil_moduleImportError
LabelValueMappingr:   ro   	getLoggerri   r4   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   r9   SERVICE_NAMESPACESERVICE_INSTANCE_IDSERVICE_VERSIONTELEMETRY_SDK_NAMETELEMETRY_SDK_VERSIONTELEMETRY_AUTO_VERSIONTELEMETRY_SDK_LANGUAGEr   r   rG   r7   ABCrz   r   r   r   r   ru   r6   rH   r!   r   <module>r<     s%  *^    	   
     ' '  6 
 > 4# #	"F 
^^CO,
			8	$#22%66 !..,DD #22!..)>> (<< +BB ((	

$
$!.."00((	((	((	$44"00':: ,== .AA '33 (55 .AA /BB 0DD .AA /CC 0DD 1FF .@@ /BB '33 (55 ,<< ->> #22

$
$**
 ,,':: ,DD ,DD $44)>> )>> "00)>> ,DD 0LL !..&88 (<< $44':: *@@ +BB +BB ")*="> C >U
 U
p 2,O9 $sww $*+ *4('. ('VQ
) Q
h
, 
  37)%{{-.)%ooh/)% )% 	)%q  		s   5O2 2O<;O<