Skip to content

Commit

Permalink
Update runtime metrics to follow semantic conventions (#1735)
Browse files Browse the repository at this point in the history
  • Loading branch information
liustanley authored Apr 3, 2023
1 parent 20d2cc3 commit e4d42e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- `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))

### Added

- Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"system.network.io": ["transmit", "receive"],
"system.network.connections": ["family", "type"],
"system.thread_count": None
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"process.runtime.memory": ["rss", "vms"],
"process.runtime.cpu.time": ["user", "system"],
}
Usage
Expand All @@ -61,8 +61,8 @@
"system.memory.usage": ["used", "free", "cached"],
"system.cpu.time": ["idle", "user", "system", "irq"],
"system.network.io": ["transmit", "receive"],
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"process.runtime.memory": ["rss", "vms"],
"process.runtime.cpu.time": ["user", "system"],
}
SystemMetricsInstrumentor(config=configuration).instrument()
Expand Down Expand Up @@ -102,9 +102,9 @@
"system.network.io": ["transmit", "receive"],
"system.network.connections": ["family", "type"],
"system.thread_count": None,
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"runtime.gc_count": None,
"process.runtime.memory": ["rss", "vms"],
"process.runtime.cpu.time": ["user", "system"],
"process.runtime.gc_count": None,
}


Expand Down Expand Up @@ -323,25 +323,25 @@ def _instrument(self, **kwargs):
description="System active threads count",
)

if "runtime.memory" in self._config:
self._meter.create_observable_counter(
name=f"runtime.{self._python_implementation}.memory",
if "process.runtime.memory" in self._config:
self._meter.create_observable_up_down_counter(
name=f"process.runtime.{self._python_implementation}.memory",
callbacks=[self._get_runtime_memory],
description=f"Runtime {self._python_implementation} memory",
unit="bytes",
)

if "runtime.cpu.time" in self._config:
if "process.runtime.cpu.time" in self._config:
self._meter.create_observable_counter(
name=f"runtime.{self._python_implementation}.cpu_time",
name=f"process.runtime.{self._python_implementation}.cpu_time",
callbacks=[self._get_runtime_cpu_time],
description=f"Runtime {self._python_implementation} CPU time",
unit="seconds",
)

if "runtime.gc_count" in self._config:
if "process.runtime.gc_count" in self._config:
self._meter.create_observable_counter(
name=f"runtime.{self._python_implementation}.gc_count",
name=f"process.runtime.{self._python_implementation}.gc_count",
callbacks=[self._get_runtime_gc_count],
description=f"Runtime {self._python_implementation} GC count",
unit="bytes",
Expand Down Expand Up @@ -618,7 +618,7 @@ def _get_runtime_memory(
) -> Iterable[Observation]:
"""Observer callback for runtime memory"""
proc_memory = self._proc.memory_info()
for metric in self._config["runtime.memory"]:
for metric in self._config["process.runtime.memory"]:
if hasattr(proc_memory, metric):
self._runtime_memory_labels["type"] = metric
yield Observation(
Expand All @@ -631,7 +631,7 @@ def _get_runtime_cpu_time(
) -> Iterable[Observation]:
"""Observer callback for runtime CPU time"""
proc_cpu = self._proc.cpu_times()
for metric in self._config["runtime.cpu.time"]:
for metric in self._config["process.runtime.cpu.time"]:
if hasattr(proc_cpu, metric):
self._runtime_cpu_time_labels["type"] = metric
yield Observation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def test_system_metrics_instrument(self):
"system.network.io",
"system.network.connections",
"system.thread_count",
f"runtime.{self.implementation}.memory",
f"runtime.{self.implementation}.cpu_time",
f"runtime.{self.implementation}.gc_count",
f"process.runtime.{self.implementation}.memory",
f"process.runtime.{self.implementation}.cpu_time",
f"process.runtime.{self.implementation}.gc_count",
]

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

def test_runtime_metrics_instrument(self):
runtime_config = {
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"runtime.gc_count": None,
"process.runtime.memory": ["rss", "vms"],
"process.runtime.cpu.time": ["user", "system"],
"process.runtime.gc_count": None,
}

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

observer_names = [
f"runtime.{self.implementation}.memory",
f"runtime.{self.implementation}.cpu_time",
f"runtime.{self.implementation}.gc_count",
f"process.runtime.{self.implementation}.memory",
f"process.runtime.{self.implementation}.cpu_time",
f"process.runtime.{self.implementation}.gc_count",
]

for observer in metric_names:
Expand Down Expand Up @@ -750,7 +750,9 @@ def test_runtime_memory(self, mock_process_memory_info):
_SystemMetricsResult({"type": "rss"}, 1),
_SystemMetricsResult({"type": "vms"}, 2),
]
self._test_metrics(f"runtime.{self.implementation}.memory", expected)
self._test_metrics(
f"process.runtime.{self.implementation}.memory", expected
)

@mock.patch("psutil.Process.cpu_times")
def test_runtime_cpu_time(self, mock_process_cpu_times):
Expand All @@ -764,7 +766,9 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):
_SystemMetricsResult({"type": "user"}, 1.1),
_SystemMetricsResult({"type": "system"}, 2.2),
]
self._test_metrics(f"runtime.{self.implementation}.cpu_time", expected)
self._test_metrics(
f"process.runtime.{self.implementation}.cpu_time", expected
)

@mock.patch("gc.get_count")
def test_runtime_get_count(self, mock_gc_get_count):
Expand All @@ -775,4 +779,6 @@ def test_runtime_get_count(self, mock_gc_get_count):
_SystemMetricsResult({"count": "1"}, 2),
_SystemMetricsResult({"count": "2"}, 3),
]
self._test_metrics(f"runtime.{self.implementation}.gc_count", expected)
self._test_metrics(
f"process.runtime.{self.implementation}.gc_count", expected
)

0 comments on commit e4d42e6

Please sign in to comment.