4242 "system.network.connections": ["family", "type"],
4343 "runtime.memory": ["rss", "vms"],
4444 "runtime.cpu.time": ["user", "system"],
45- "runtime.gc_count": None
45+ "runtime.gc_count": None,
46+ "runtime.threading.active_count": None
4647 }
4748
4849Usage
8081
8182import gc
8283import os
84+ import threading
8385from platform import python_implementation
8486from typing import Collection , Dict , Iterable , List , Optional
8587
118120 "runtime.memory" : ["rss" , "vms" ],
119121 "runtime.cpu.time" : ["user" , "system" ],
120122 "runtime.gc_count" : None ,
123+ "runtime.threading.active_count" : None ,
121124}
122125
123126
@@ -168,6 +171,7 @@ def __init__(
168171 self ._runtime_memory_labels = self ._labels .copy ()
169172 self ._runtime_cpu_time_labels = self ._labels .copy ()
170173 self ._runtime_gc_count_labels = self ._labels .copy ()
174+ self ._runtime_threading_active_count_labels = self ._labels .copy ()
171175
172176 def instrumentation_dependencies (self ) -> Collection [str ]:
173177 return _instruments
@@ -415,6 +419,14 @@ def _instrument(self, **kwargs):
415419 unit = "bytes" ,
416420 )
417421
422+ if "runtime.threading.active_count" in self ._config :
423+ self ._meter .create_observable_gauge (
424+ name = f"runtime.{ self ._python_implementation } .threading.active_count" ,
425+ callbacks = [self ._get_runtime_threading_active_count ],
426+ description = f"Runtime { self ._python_implementation } active threads count" ,
427+ unit = "threads" ,
428+ )
429+
418430 def _uninstrument (self , ** __ ):
419431 pass
420432
@@ -747,3 +759,11 @@ def _get_runtime_gc_count(
747759 for index , count in enumerate (gc .get_count ()):
748760 self ._runtime_gc_count_labels ["count" ] = str (index )
749761 yield Observation (count , self ._runtime_gc_count_labels .copy ())
762+
763+ def _get_runtime_threading_active_count (
764+ self , options : CallbackOptions
765+ ) -> Iterable [Observation ]:
766+ """Observer callback for threading active count"""
767+ yield Observation (
768+ threading .active_count (), self ._runtime_threading_active_count_labels
769+ )
0 commit comments