Skip to content

Commit e4d42e6

Browse files
authored
Update runtime metrics to follow semantic conventions (#1735)
1 parent 20d2cc3 commit e4d42e6

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735))
11+
1012
### Added
1113

1214
- Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"system.network.io": ["transmit", "receive"],
3535
"system.network.connections": ["family", "type"],
3636
"system.thread_count": None
37-
"runtime.memory": ["rss", "vms"],
38-
"runtime.cpu.time": ["user", "system"],
37+
"process.runtime.memory": ["rss", "vms"],
38+
"process.runtime.cpu.time": ["user", "system"],
3939
}
4040
4141
Usage
@@ -61,8 +61,8 @@
6161
"system.memory.usage": ["used", "free", "cached"],
6262
"system.cpu.time": ["idle", "user", "system", "irq"],
6363
"system.network.io": ["transmit", "receive"],
64-
"runtime.memory": ["rss", "vms"],
65-
"runtime.cpu.time": ["user", "system"],
64+
"process.runtime.memory": ["rss", "vms"],
65+
"process.runtime.cpu.time": ["user", "system"],
6666
}
6767
SystemMetricsInstrumentor(config=configuration).instrument()
6868
@@ -102,9 +102,9 @@
102102
"system.network.io": ["transmit", "receive"],
103103
"system.network.connections": ["family", "type"],
104104
"system.thread_count": None,
105-
"runtime.memory": ["rss", "vms"],
106-
"runtime.cpu.time": ["user", "system"],
107-
"runtime.gc_count": None,
105+
"process.runtime.memory": ["rss", "vms"],
106+
"process.runtime.cpu.time": ["user", "system"],
107+
"process.runtime.gc_count": None,
108108
}
109109

110110

@@ -323,25 +323,25 @@ def _instrument(self, **kwargs):
323323
description="System active threads count",
324324
)
325325

326-
if "runtime.memory" in self._config:
327-
self._meter.create_observable_counter(
328-
name=f"runtime.{self._python_implementation}.memory",
326+
if "process.runtime.memory" in self._config:
327+
self._meter.create_observable_up_down_counter(
328+
name=f"process.runtime.{self._python_implementation}.memory",
329329
callbacks=[self._get_runtime_memory],
330330
description=f"Runtime {self._python_implementation} memory",
331331
unit="bytes",
332332
)
333333

334-
if "runtime.cpu.time" in self._config:
334+
if "process.runtime.cpu.time" in self._config:
335335
self._meter.create_observable_counter(
336-
name=f"runtime.{self._python_implementation}.cpu_time",
336+
name=f"process.runtime.{self._python_implementation}.cpu_time",
337337
callbacks=[self._get_runtime_cpu_time],
338338
description=f"Runtime {self._python_implementation} CPU time",
339339
unit="seconds",
340340
)
341341

342-
if "runtime.gc_count" in self._config:
342+
if "process.runtime.gc_count" in self._config:
343343
self._meter.create_observable_counter(
344-
name=f"runtime.{self._python_implementation}.gc_count",
344+
name=f"process.runtime.{self._python_implementation}.gc_count",
345345
callbacks=[self._get_runtime_gc_count],
346346
description=f"Runtime {self._python_implementation} GC count",
347347
unit="bytes",
@@ -618,7 +618,7 @@ def _get_runtime_memory(
618618
) -> Iterable[Observation]:
619619
"""Observer callback for runtime memory"""
620620
proc_memory = self._proc.memory_info()
621-
for metric in self._config["runtime.memory"]:
621+
for metric in self._config["process.runtime.memory"]:
622622
if hasattr(proc_memory, metric):
623623
self._runtime_memory_labels["type"] = metric
624624
yield Observation(
@@ -631,7 +631,7 @@ def _get_runtime_cpu_time(
631631
) -> Iterable[Observation]:
632632
"""Observer callback for runtime CPU time"""
633633
proc_cpu = self._proc.cpu_times()
634-
for metric in self._config["runtime.cpu.time"]:
634+
for metric in self._config["process.runtime.cpu.time"]:
635635
if hasattr(proc_cpu, metric):
636636
self._runtime_cpu_time_labels["type"] = metric
637637
yield Observation(

instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def test_system_metrics_instrument(self):
114114
"system.network.io",
115115
"system.network.connections",
116116
"system.thread_count",
117-
f"runtime.{self.implementation}.memory",
118-
f"runtime.{self.implementation}.cpu_time",
119-
f"runtime.{self.implementation}.gc_count",
117+
f"process.runtime.{self.implementation}.memory",
118+
f"process.runtime.{self.implementation}.cpu_time",
119+
f"process.runtime.{self.implementation}.gc_count",
120120
]
121121

122122
for observer in metric_names:
@@ -125,9 +125,9 @@ def test_system_metrics_instrument(self):
125125

126126
def test_runtime_metrics_instrument(self):
127127
runtime_config = {
128-
"runtime.memory": ["rss", "vms"],
129-
"runtime.cpu.time": ["user", "system"],
130-
"runtime.gc_count": None,
128+
"process.runtime.memory": ["rss", "vms"],
129+
"process.runtime.cpu.time": ["user", "system"],
130+
"process.runtime.gc_count": None,
131131
}
132132

133133
reader = InMemoryMetricReader()
@@ -143,9 +143,9 @@ def test_runtime_metrics_instrument(self):
143143
self.assertEqual(len(metric_names), 3)
144144

145145
observer_names = [
146-
f"runtime.{self.implementation}.memory",
147-
f"runtime.{self.implementation}.cpu_time",
148-
f"runtime.{self.implementation}.gc_count",
146+
f"process.runtime.{self.implementation}.memory",
147+
f"process.runtime.{self.implementation}.cpu_time",
148+
f"process.runtime.{self.implementation}.gc_count",
149149
]
150150

151151
for observer in metric_names:
@@ -750,7 +750,9 @@ def test_runtime_memory(self, mock_process_memory_info):
750750
_SystemMetricsResult({"type": "rss"}, 1),
751751
_SystemMetricsResult({"type": "vms"}, 2),
752752
]
753-
self._test_metrics(f"runtime.{self.implementation}.memory", expected)
753+
self._test_metrics(
754+
f"process.runtime.{self.implementation}.memory", expected
755+
)
754756

755757
@mock.patch("psutil.Process.cpu_times")
756758
def test_runtime_cpu_time(self, mock_process_cpu_times):
@@ -764,7 +766,9 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):
764766
_SystemMetricsResult({"type": "user"}, 1.1),
765767
_SystemMetricsResult({"type": "system"}, 2.2),
766768
]
767-
self._test_metrics(f"runtime.{self.implementation}.cpu_time", expected)
769+
self._test_metrics(
770+
f"process.runtime.{self.implementation}.cpu_time", expected
771+
)
768772

769773
@mock.patch("gc.get_count")
770774
def test_runtime_get_count(self, mock_gc_get_count):
@@ -775,4 +779,6 @@ def test_runtime_get_count(self, mock_gc_get_count):
775779
_SystemMetricsResult({"count": "1"}, 2),
776780
_SystemMetricsResult({"count": "2"}, 3),
777781
]
778-
self._test_metrics(f"runtime.{self.implementation}.gc_count", expected)
782+
self._test_metrics(
783+
f"process.runtime.{self.implementation}.gc_count", expected
784+
)

0 commit comments

Comments
 (0)