Skip to content

Commit 445ed10

Browse files
authored
Stop implicitly emitting deprecated process runtime metrics (#932)
1 parent 28668c0 commit 445ed10

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

docs/integrations/system-metrics.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ By default, `instrument_system_metrics` collects only the metrics it needs to di
2828

2929
```py
3030
logfire.instrument_system_metrics({
31-
'process.runtime.cpu.utilization': None, # (1)!
31+
'process.cpu.utilization': None, # (1)!
3232
'system.cpu.simple_utilization': None, # (2)!
3333
'system.memory.utilization': ['available'], # (3)!
3434
'system.swap.utilization': ['used'], # (4)!
3535
})
3636
```
3737

38-
1. `process.runtime.cpu.utilization` will lead to exporting a metric that is actually named `process.runtime.cpython.cpu.utilization` or a similar name depending on the Python implementation used. The `None` value means that there are no fields to configure for this metric. The value of this metric is [`psutil.Process().cpu_percent()`](https://psutil.readthedocs.io/en/latest/#psutil.Process.cpu_percent)`/ 100`, i.e. the fraction of CPU time used by this process, where 1 means using 100% of a single CPU core. The value can be greater than 1 if the process uses multiple cores. In the next major release, the default will instead emit `process.cpu.core_utilization`, which is the same metric but with a simpler name.
39-
2. The `None` value means that there are no fields to configure for this metric. The value of this metric is [`psutil.cpu_percent()`](https://psutil.readthedocs.io/en/latest/#psutil.cpu_percent)`/ 100`, i.e. the fraction of CPU time used by the whole system, where 1 means using 100% of all CPU cores.
38+
1. The `None` value means that there are no fields to configure for this metric. The value of this metric is [`psutil.Process().cpu_percent()`](https://psutil.readthedocs.io/en/latest/#psutil.Process.cpu_percent)`/100`, i.e. the fraction of CPU time used by this process, where 1 means using 100% of a single CPU core. The value can be greater than 1 if the process uses multiple cores.
39+
2. The `None` value means that there are no fields to configure for this metric. The value of this metric is [`psutil.cpu_percent()`](https://psutil.readthedocs.io/en/latest/#psutil.cpu_percent)`/100`, i.e. the fraction of CPU time used by the whole system, where 1 means using 100% of all CPU cores.
4040
3. The value here is a list of 'modes' of memory. The full list can be seen in the [`psutil` documentation](https://psutil.readthedocs.io/en/latest/#psutil.virtual_memory). `available` is "the memory that can be given instantly to processes without the system going into swap. This is calculated by summing different memory metrics that vary depending on the platform. It is supposed to be used to monitor actual memory usage in a cross platform fashion." The value of the metric is a number between 0 and 1, and subtracting the value from 1 gives the fraction of memory used.
4141
4. This is the fraction of available swap used. The value is a number between 0 and 1.
4242

@@ -78,13 +78,6 @@ logfire.instrument_system_metrics({
7878
'process.memory.usage': None,
7979
'process.memory.virtual': None,
8080
'process.thread.count': None,
81-
# These are deprecated and equivalent to some of the above.
82-
# base='full' will stop including them in the next major release.
83-
'process.runtime.memory': ['rss', 'vms'],
84-
'process.runtime.cpu.time': ['user', 'system'],
85-
'process.runtime.thread_count': None,
86-
'process.runtime.cpu.utilization': None,
87-
'process.runtime.context_switches': ['involuntary', 'voluntary'],
8881
})
8982
```
9083

logfire/_internal/integrations/system_metrics.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@
5353
'process.memory.virtual',
5454
'process.thread.count',
5555
'process.runtime.gc_count',
56-
# ##### These are deprecated:
57-
'process.runtime.memory',
58-
'process.runtime.cpu.time',
59-
'process.runtime.thread_count',
60-
'process.runtime.cpu.utilization',
61-
'process.runtime.context_switches',
6256
]
6357
] = Literal[ # type: ignore # but pyright doesn't like it
6458
'system.cpu.simple_utilization',
@@ -86,12 +80,6 @@
8680
'process.memory.virtual',
8781
'process.thread.count',
8882
'process.runtime.gc_count',
89-
# ##### These are deprecated:
90-
'process.runtime.memory',
91-
'process.runtime.cpu.time',
92-
'process.runtime.thread_count',
93-
'process.runtime.cpu.utilization',
94-
'process.runtime.context_switches',
9583
]
9684

9785
Config = dict[MetricName, Optional[Iterable[str]]]
@@ -109,6 +97,7 @@
10997
FULL_CONFIG: Config = {
11098
**cast(Config, _DEFAULT_CONFIG),
11199
'system.cpu.simple_utilization': None,
100+
'process.cpu.utilization': None,
112101
'process.cpu.core_utilization': None,
113102
'system.cpu.time': CPU_FIELDS,
114103
'system.cpu.utilization': CPU_FIELDS,
@@ -125,8 +114,17 @@
125114
# upstream pr: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2008
126115
FULL_CONFIG.pop('system.network.connections', None)
127116

117+
for _deprecated in [
118+
'process.runtime.memory',
119+
'process.runtime.cpu.time',
120+
'process.runtime.thread_count',
121+
'process.runtime.cpu.utilization',
122+
'process.runtime.context_switches',
123+
]:
124+
FULL_CONFIG.pop(_deprecated, None) # type: ignore
125+
128126
BASIC_CONFIG: Config = {
129-
'process.runtime.cpu.utilization': None,
127+
'process.cpu.utilization': None,
130128
'system.cpu.simple_utilization': None,
131129
# The actually used memory ratio can be calculated as `1 - available`.
132130
'system.memory.utilization': ['available'],
@@ -156,10 +154,11 @@ def instrument_system_metrics(logfire_instance: Logfire, config: Config | None =
156154
if 'process.cpu.core_utilization' in config:
157155
measure_process_cpu_core_utilization(logfire_instance)
158156

159-
if 'process.runtime.cpu.utilization' in config:
157+
if 'process.runtime.cpu.utilization' in config: # type: ignore
160158
# Override OTEL here, see comment in measure_process_runtime_cpu_utilization.<locals>.callback.
159+
# (The name is also deprecated by OTEL, but that's not really important)
161160
measure_process_runtime_cpu_utilization(logfire_instance)
162-
del config['process.runtime.cpu.utilization']
161+
del config['process.runtime.cpu.utilization'] # type: ignore
163162

164163
if 'process.cpu.utilization' in config:
165164
# Override OTEL here to avoid emitting 0 in the first measurement.

tests/otel_integrations/test_system_metrics.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_default_system_metrics_collection(metrics_reader: InMemoryMetricReader)
2727
logfire.instrument_system_metrics()
2828
assert get_collected_metric_names(metrics_reader) == snapshot(
2929
[
30-
'process.runtime.cpython.cpu.utilization',
30+
'process.cpu.utilization',
3131
'system.cpu.simple_utilization',
3232
'system.memory.utilization',
3333
'system.swap.utilization',
@@ -46,12 +46,7 @@ def test_all_system_metrics_collection(metrics_reader: InMemoryMetricReader) ->
4646
'process.memory.usage',
4747
'process.memory.virtual',
4848
'process.open_file_descriptor.count',
49-
'process.runtime.cpython.context_switches',
50-
'process.runtime.cpython.cpu.utilization',
51-
'process.runtime.cpython.cpu_time',
5249
'process.runtime.cpython.gc_count',
53-
'process.runtime.cpython.memory',
54-
'process.runtime.cpython.thread_count',
5550
'process.thread.count',
5651
'system.cpu.simple_utilization',
5752
'system.cpu.time',
@@ -72,6 +67,12 @@ def test_all_system_metrics_collection(metrics_reader: InMemoryMetricReader) ->
7267
)
7368

7469

70+
def test_measure_process_runtime_cpu_utilization(metrics_reader: InMemoryMetricReader) -> None:
71+
# This metric is now deprecated by OTEL, but there isn't a strong reason to stop allowing it when requested
72+
logfire.instrument_system_metrics({'process.runtime.cpu.utilization': None}, base=None) # type: ignore
73+
assert get_collected_metric_names(metrics_reader) == ['process.runtime.cpython.cpu.utilization']
74+
75+
7576
def test_custom_system_metrics_collection(metrics_reader: InMemoryMetricReader) -> None:
7677
logfire.instrument_system_metrics(
7778
{
@@ -92,7 +93,7 @@ def test_custom_system_metrics_collection(metrics_reader: InMemoryMetricReader)
9293

9394
def test_basic_base():
9495
assert get_base_config('basic') == {
95-
'process.runtime.cpu.utilization': None,
96+
'process.cpu.utilization': None,
9697
'system.cpu.simple_utilization': None,
9798
'system.memory.utilization': ['available'],
9899
'system.swap.utilization': ['used'],
@@ -158,16 +159,10 @@ def test_full_base():
158159
'process.memory.virtual': None,
159160
'process.cpu.time': ['user', 'system'],
160161
# There's no reason for OTel to give a value here, so the docs say `None`
161-
'process.cpu.utilization': ['user', 'system'],
162+
'process.cpu.utilization': None,
162163
'process.cpu.core_utilization': None,
163164
'process.thread.count': None,
164165
'process.context_switches': ['involuntary', 'voluntary'],
165-
# These are deprecated:
166-
'process.runtime.memory': ['rss', 'vms'],
167-
'process.runtime.cpu.time': ['user', 'system'],
168-
'process.runtime.cpu.utilization': None,
169-
'process.runtime.thread_count': None,
170-
'process.runtime.context_switches': ['involuntary', 'voluntary'],
171166
}, 'Docs and the MetricName type need to be updated if this test fails'
172167

173168

0 commit comments

Comments
 (0)