Skip to content

Conversation

dabico
Copy link

@dabico dabico commented Sep 7, 2025

Description

Changes:

  • Default and user-specified instances of configuration dictionaries are now deeply copied when passed to SystemMetricsInstrumentor.
  • On macOS, if the user-specified config contains system.network.connections, then the metric will be removed and a warning is logged.
  • On Linux, if the user-specified config contains system.swap.usage or system.swap.utilization, the sin and sout states will be removed from both metrics and a warning is logged.
  • Any RuntimeWarning emitted by psutil is (narrowly) suppressed whenever psutil.swap_memory is called in gauge callbacks.

Fixes #3740

Type of change

Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added a dedicated test for this functionality:

instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py::TestSystemMetrics::test_system_swap_states_removed_when_vmstat_missing

Ran it against several Python versions as follows:

tox -e py39-test-instrumentation-system-metrics
tox -e py310-test-instrumentation-system-metrics
tox -e py311-test-instrumentation-system-metrics
tox -e py312-test-instrumentation-system-metrics
tox -e py313-test-instrumentation-system-metrics

Note that it's set to only run on Linux.

Does This PR Require a Core Repo Change?

No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link

linux-foundation-easycla bot commented Sep 7, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@dabico
Copy link
Author

dabico commented Sep 7, 2025

Spending some more time with the code, I came to the realisation I over-compensated with the metric removals. The error message states that sin and sout can't be computed, but these two states aren't part of the _DEFAULT configuration. A more desirable course of action would be to remove these two states from the passed config and issue a log warning if the trigger conditions are met. Will rework this.

@dabico dabico force-pushed the swap branch 2 times, most recently from 64a6eb0 to 82bf62b Compare September 8, 2025 21:21
@dabico dabico changed the title Remove system.swap.* metrics if they can not be computed Remove sin & sout states from system.swap.* if they can not be computed Sep 8, 2025
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

Some system.swap.* metric states are not available in sandbox runtimes
1 participant