Skip to content

Commit 9e0c2ce

Browse files
authored
Rename Measurement to Observation (#1061)
1 parent c909353 commit 9e0c2ce

File tree

2 files changed

+41
-38
lines changed
  • .github/workflows
  • instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics

2 files changed

+41
-38
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: 516bf8ad04d628b20c103622f390f7a536142e9a
9+
CORE_REPO_SHA: 7647a11774a029ead5e8ac864e6f55e9d06f463e
1010

1111
jobs:
1212
build:

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

+40-37
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@
7777
import psutil
7878

7979
from opentelemetry._metrics import get_meter
80-
from opentelemetry._metrics.measurement import Measurement
80+
81+
# FIXME Remove this pyling disabling line when Github issue is cleared
82+
# pylint: disable=no-name-in-module
83+
from opentelemetry._metrics.observation import Observation
8184
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
8285
from opentelemetry.instrumentation.system_metrics.package import _instruments
8386
from opentelemetry.instrumentation.system_metrics.version import __version__
@@ -318,18 +321,18 @@ def _instrument(self, **kwargs):
318321
def _uninstrument(self, **__):
319322
pass
320323

321-
def _get_system_cpu_time(self) -> Iterable[Measurement]:
324+
def _get_system_cpu_time(self) -> Iterable[Observation]:
322325
"""Observer callback for system CPU time"""
323326
for cpu, times in enumerate(psutil.cpu_times(percpu=True)):
324327
for metric in self._config["system.cpu.time"]:
325328
if hasattr(times, metric):
326329
self._system_cpu_time_labels["state"] = metric
327330
self._system_cpu_time_labels["cpu"] = cpu + 1
328-
yield Measurement(
331+
yield Observation(
329332
getattr(times, metric), self._system_cpu_time_labels
330333
)
331334

332-
def _get_system_cpu_utilization(self) -> Iterable[Measurement]:
335+
def _get_system_cpu_utilization(self) -> Iterable[Observation]:
333336
"""Observer callback for system CPU utilization"""
334337

335338
for cpu, times_percent in enumerate(
@@ -339,95 +342,95 @@ def _get_system_cpu_utilization(self) -> Iterable[Measurement]:
339342
if hasattr(times_percent, metric):
340343
self._system_cpu_utilization_labels["state"] = metric
341344
self._system_cpu_utilization_labels["cpu"] = cpu + 1
342-
yield Measurement(
345+
yield Observation(
343346
getattr(times_percent, metric) / 100,
344347
self._system_cpu_utilization_labels,
345348
)
346349

347-
def _get_system_memory_usage(self) -> Iterable[Measurement]:
350+
def _get_system_memory_usage(self) -> Iterable[Observation]:
348351
"""Observer callback for memory usage"""
349352
virtual_memory = psutil.virtual_memory()
350353
for metric in self._config["system.memory.usage"]:
351354
self._system_memory_usage_labels["state"] = metric
352355
if hasattr(virtual_memory, metric):
353-
yield Measurement(
356+
yield Observation(
354357
getattr(virtual_memory, metric),
355358
self._system_memory_usage_labels,
356359
)
357360

358-
def _get_system_memory_utilization(self) -> Iterable[Measurement]:
361+
def _get_system_memory_utilization(self) -> Iterable[Observation]:
359362
"""Observer callback for memory utilization"""
360363
system_memory = psutil.virtual_memory()
361364

362365
for metric in self._config["system.memory.utilization"]:
363366
self._system_memory_utilization_labels["state"] = metric
364367
if hasattr(system_memory, metric):
365-
yield Measurement(
368+
yield Observation(
366369
getattr(system_memory, metric) / system_memory.total,
367370
self._system_memory_utilization_labels,
368371
)
369372

370-
def _get_system_swap_usage(self) -> Iterable[Measurement]:
373+
def _get_system_swap_usage(self) -> Iterable[Observation]:
371374
"""Observer callback for swap usage"""
372375
system_swap = psutil.swap_memory()
373376

374377
for metric in self._config["system.swap.usage"]:
375378
self._system_swap_usage_labels["state"] = metric
376379
if hasattr(system_swap, metric):
377-
yield Measurement(
380+
yield Observation(
378381
getattr(system_swap, metric),
379382
self._system_swap_usage_labels,
380383
)
381384

382-
def _get_system_swap_utilization(self) -> Iterable[Measurement]:
385+
def _get_system_swap_utilization(self) -> Iterable[Observation]:
383386
"""Observer callback for swap utilization"""
384387
system_swap = psutil.swap_memory()
385388

386389
for metric in self._config["system.swap.utilization"]:
387390
if hasattr(system_swap, metric):
388391
self._system_swap_utilization_labels["state"] = metric
389-
yield Measurement(
392+
yield Observation(
390393
getattr(system_swap, metric) / system_swap.total,
391394
self._system_swap_utilization_labels,
392395
)
393396

394-
def _get_system_disk_io(self) -> Iterable[Measurement]:
397+
def _get_system_disk_io(self) -> Iterable[Observation]:
395398
"""Observer callback for disk IO"""
396399
for device, counters in psutil.disk_io_counters(perdisk=True).items():
397400
for metric in self._config["system.disk.io"]:
398401
if hasattr(counters, f"{metric}_bytes"):
399402
self._system_disk_io_labels["device"] = device
400403
self._system_disk_io_labels["direction"] = metric
401-
yield Measurement(
404+
yield Observation(
402405
getattr(counters, f"{metric}_bytes"),
403406
self._system_disk_io_labels,
404407
)
405408

406-
def _get_system_disk_operations(self) -> Iterable[Measurement]:
409+
def _get_system_disk_operations(self) -> Iterable[Observation]:
407410
"""Observer callback for disk operations"""
408411
for device, counters in psutil.disk_io_counters(perdisk=True).items():
409412
for metric in self._config["system.disk.operations"]:
410413
if hasattr(counters, f"{metric}_count"):
411414
self._system_disk_operations_labels["device"] = device
412415
self._system_disk_operations_labels["direction"] = metric
413-
yield Measurement(
416+
yield Observation(
414417
getattr(counters, f"{metric}_count"),
415418
self._system_disk_operations_labels,
416419
)
417420

418-
def _get_system_disk_time(self) -> Iterable[Measurement]:
421+
def _get_system_disk_time(self) -> Iterable[Observation]:
419422
"""Observer callback for disk time"""
420423
for device, counters in psutil.disk_io_counters(perdisk=True).items():
421424
for metric in self._config["system.disk.time"]:
422425
if hasattr(counters, f"{metric}_time"):
423426
self._system_disk_time_labels["device"] = device
424427
self._system_disk_time_labels["direction"] = metric
425-
yield Measurement(
428+
yield Observation(
426429
getattr(counters, f"{metric}_time") / 1000,
427430
self._system_disk_time_labels,
428431
)
429432

430-
def _get_system_disk_merged(self) -> Iterable[Measurement]:
433+
def _get_system_disk_merged(self) -> Iterable[Observation]:
431434
"""Observer callback for disk merged operations"""
432435

433436
# FIXME The units in the spec is 1, it seems like it should be
@@ -438,12 +441,12 @@ def _get_system_disk_merged(self) -> Iterable[Measurement]:
438441
if hasattr(counters, f"{metric}_merged_count"):
439442
self._system_disk_merged_labels["device"] = device
440443
self._system_disk_merged_labels["direction"] = metric
441-
yield Measurement(
444+
yield Observation(
442445
getattr(counters, f"{metric}_merged_count"),
443446
self._system_disk_merged_labels,
444447
)
445448

446-
def _get_system_network_dropped_packets(self) -> Iterable[Measurement]:
449+
def _get_system_network_dropped_packets(self) -> Iterable[Observation]:
447450
"""Observer callback for network dropped packets"""
448451

449452
for device, counters in psutil.net_io_counters(pernic=True).items():
@@ -456,12 +459,12 @@ def _get_system_network_dropped_packets(self) -> Iterable[Measurement]:
456459
self._system_network_dropped_packets_labels[
457460
"direction"
458461
] = metric
459-
yield Measurement(
462+
yield Observation(
460463
getattr(counters, f"drop{in_out}"),
461464
self._system_network_dropped_packets_labels,
462465
)
463466

464-
def _get_system_network_packets(self) -> Iterable[Measurement]:
467+
def _get_system_network_packets(self) -> Iterable[Observation]:
465468
"""Observer callback for network packets"""
466469

467470
for device, counters in psutil.net_io_counters(pernic=True).items():
@@ -470,25 +473,25 @@ def _get_system_network_packets(self) -> Iterable[Measurement]:
470473
if hasattr(counters, f"packets_{recv_sent}"):
471474
self._system_network_packets_labels["device"] = device
472475
self._system_network_packets_labels["direction"] = metric
473-
yield Measurement(
476+
yield Observation(
474477
getattr(counters, f"packets_{recv_sent}"),
475478
self._system_network_packets_labels,
476479
)
477480

478-
def _get_system_network_errors(self) -> Iterable[Measurement]:
481+
def _get_system_network_errors(self) -> Iterable[Observation]:
479482
"""Observer callback for network errors"""
480483
for device, counters in psutil.net_io_counters(pernic=True).items():
481484
for metric in self._config["system.network.errors"]:
482485
in_out = {"receive": "in", "transmit": "out"}[metric]
483486
if hasattr(counters, f"err{in_out}"):
484487
self._system_network_errors_labels["device"] = device
485488
self._system_network_errors_labels["direction"] = metric
486-
yield Measurement(
489+
yield Observation(
487490
getattr(counters, f"err{in_out}"),
488491
self._system_network_errors_labels,
489492
)
490493

491-
def _get_system_network_io(self) -> Iterable[Measurement]:
494+
def _get_system_network_io(self) -> Iterable[Observation]:
492495
"""Observer callback for network IO"""
493496

494497
for device, counters in psutil.net_io_counters(pernic=True).items():
@@ -497,12 +500,12 @@ def _get_system_network_io(self) -> Iterable[Measurement]:
497500
if hasattr(counters, f"bytes_{recv_sent}"):
498501
self._system_network_io_labels["device"] = device
499502
self._system_network_io_labels["direction"] = metric
500-
yield Measurement(
503+
yield Observation(
501504
getattr(counters, f"bytes_{recv_sent}"),
502505
self._system_network_io_labels,
503506
)
504507

505-
def _get_system_network_connections(self) -> Iterable[Measurement]:
508+
def _get_system_network_connections(self) -> Iterable[Observation]:
506509
"""Observer callback for network connections"""
507510
# TODO How to find the device identifier for a particular
508511
# connection?
@@ -535,35 +538,35 @@ def _get_system_network_connections(self) -> Iterable[Measurement]:
535538
}
536539

537540
for connection_counter in connection_counters.values():
538-
yield Measurement(
541+
yield Observation(
539542
connection_counter["counter"],
540543
connection_counter["labels"],
541544
)
542545

543-
def _get_runtime_memory(self) -> Iterable[Measurement]:
546+
def _get_runtime_memory(self) -> Iterable[Observation]:
544547
"""Observer callback for runtime memory"""
545548
proc_memory = self._proc.memory_info()
546549
for metric in self._config["runtime.memory"]:
547550
if hasattr(proc_memory, metric):
548551
self._runtime_memory_labels["type"] = metric
549-
yield Measurement(
552+
yield Observation(
550553
getattr(proc_memory, metric),
551554
self._runtime_memory_labels,
552555
)
553556

554-
def _get_runtime_cpu_time(self) -> Iterable[Measurement]:
557+
def _get_runtime_cpu_time(self) -> Iterable[Observation]:
555558
"""Observer callback for runtime CPU time"""
556559
proc_cpu = self._proc.cpu_times()
557560
for metric in self._config["runtime.cpu.time"]:
558561
if hasattr(proc_cpu, metric):
559562
self._runtime_cpu_time_labels["type"] = metric
560-
yield Measurement(
563+
yield Observation(
561564
getattr(proc_cpu, metric),
562565
self._runtime_cpu_time_labels,
563566
)
564567

565-
def _get_runtime_gc_count(self) -> Iterable[Measurement]:
568+
def _get_runtime_gc_count(self) -> Iterable[Observation]:
566569
"""Observer callback for garbage collection"""
567570
for index, count in enumerate(gc.get_count()):
568571
self._runtime_gc_count_labels["count"] = str(index)
569-
yield Measurement(count, self._runtime_gc_count_labels)
572+
yield Observation(count, self._runtime_gc_count_labels)

0 commit comments

Comments
 (0)