File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
src/opentelemetry/sdk/resources Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717 ([ #2653 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2653 ) )
1818- Add variadic arguments to metric exporter/reader interfaces
1919 ([ #2654 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2654 ) )
20+ - Added a ` opentelemetry.sdk.resources.ProcessResourceDetector ` that adds the
21+ 'process.runtime.{name,version,description}' resource attributes when used
22+ with the ` opentelemetry.sdk.resources.get_aggregated_resources ` API
23+ ([ #2660 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2660 ) )
2024- Move Metrics API behind internal package
2125 ([ #2651 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2651 ) )
2226
Original file line number Diff line number Diff line change 5959import concurrent .futures
6060import logging
6161import os
62+ import sys
6263import typing
6364from json import dumps
6465
@@ -286,6 +287,28 @@ def detect(self) -> "Resource":
286287 return Resource (env_resource_map )
287288
288289
290+ class ProcessResourceDetector (ResourceDetector ):
291+ # pylint: disable=no-self-use
292+ def detect (self ) -> "Resource" :
293+ _runtime_version = "." .join (
294+ map (
295+ str ,
296+ sys .version_info [:3 ]
297+ if sys .version_info .releaselevel == "final"
298+ and not sys .version_info .serial
299+ else sys .version_info ,
300+ )
301+ )
302+
303+ return Resource (
304+ {
305+ PROCESS_RUNTIME_DESCRIPTION : sys .version ,
306+ PROCESS_RUNTIME_NAME : sys .implementation .name ,
307+ PROCESS_RUNTIME_VERSION : _runtime_version ,
308+ }
309+ )
310+
311+
289312def get_aggregated_resources (
290313 detectors : typing .List ["ResourceDetector" ],
291314 initial_resource : typing .Optional [Resource ] = None ,
Original file line number Diff line number Diff line change @@ -516,3 +516,22 @@ def test_service_name_env_precedence(self):
516516 detector .detect (),
517517 resources .Resource ({"service.name" : "from-service-name" }),
518518 )
519+
520+ def test_process_detector (self ):
521+ initial_resource = resources .Resource ({"foo" : "bar" })
522+ aggregated_resource = resources .get_aggregated_resources (
523+ [resources .ProcessResourceDetector ()], initial_resource
524+ )
525+
526+ self .assertIn (
527+ resources .PROCESS_RUNTIME_NAME ,
528+ aggregated_resource .attributes .keys (),
529+ )
530+ self .assertIn (
531+ resources .PROCESS_RUNTIME_DESCRIPTION ,
532+ aggregated_resource .attributes .keys (),
533+ )
534+ self .assertIn (
535+ resources .PROCESS_RUNTIME_VERSION ,
536+ aggregated_resource .attributes .keys (),
537+ )
You can’t perform that action at this time.
0 commit comments