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
17
17
([ #2653 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2653 ) )
18
18
- Add variadic arguments to metric exporter/reader interfaces
19
19
([ #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 ) )
20
24
- Move Metrics API behind internal package
21
25
([ #2651 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2651 ) )
22
26
Original file line number Diff line number Diff line change 59
59
import concurrent .futures
60
60
import logging
61
61
import os
62
+ import sys
62
63
import typing
63
64
from json import dumps
64
65
@@ -286,6 +287,28 @@ def detect(self) -> "Resource":
286
287
return Resource (env_resource_map )
287
288
288
289
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
+
289
312
def get_aggregated_resources (
290
313
detectors : typing .List ["ResourceDetector" ],
291
314
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):
516
516
detector .detect (),
517
517
resources .Resource ({"service.name" : "from-service-name" }),
518
518
)
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