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

System metrics instrumentation looks for wrong config key for network instruments #3005

Closed
alexmojaki opened this issue Nov 14, 2024 · 1 comment · Fixed by #3025
Closed
Labels
bug Something isn't working

Comments

@alexmojaki
Copy link
Contributor

alexmojaki commented Nov 14, 2024

Describe your environment

opentelemetry-instrumentation-system-metrics==0.49b1

What happened?

The instruments system.network.packets and system.network.io are created if those strings are in the config, but the callbacks look for the wrong key system.network.dropped.packets.

Steps to Reproduce

This script configures each instrument in isolation to find errors like this.

from opentelemetry.instrumentation.system_metrics import (
    _DEFAULT_CONFIG,
    SystemMetricsInstrumentor,
)
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import InMemoryMetricReader

for k, v in _DEFAULT_CONFIG.items():
    meter_provider = MeterProvider([InMemoryMetricReader()])
    instrumentor = SystemMetricsInstrumentor(config={k: v})
    instrumentor.instrument(meter_provider=meter_provider)
    meter_provider.force_flush()
    instrumentor.uninstrument()

Expected Result

No errors

Actual Result

Callback failed for instrument system.network.packets.
Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/sdk/metrics/_internal/instrument.py", line 136, in callback
    for api_measurement in callback(callback_options):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/system_metrics/__init__.py", line 598, in _get_system_network_packets
    for metric in self._config["system.network.dropped.packets"]:
                  ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'system.network.dropped.packets'

Callback failed for instrument system.network.io.
Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/sdk/metrics/_internal/instrument.py", line 136, in callback
    for api_measurement in callback(callback_options):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/system_metrics/__init__.py", line 629, in _get_system_network_io
    for metric in self._config["system.network.dropped.packets"]:
                  ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'system.network.dropped.packets'

Additional context

In general the architecture here seems very prone to these kinds of copy-paste mistakes.

Would you like to implement a fix?

No

@xrmx
Copy link
Contributor

xrmx commented Nov 18, 2024

Good catch, fun how we are supposed to have green tests asserting things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants