Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runtime metrics to follow semantic conventions #1735

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-instrumentation-requests` Replace `name_callback` and `span_callback` with standard `response_hook` and `request_hook` callbacks
([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670))
- `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))
liustanley marked this conversation as resolved.
Show resolved Hide resolved

## Version 1.16.0/0.37b0 (2023-02-17)

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
)