open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
733 stars 604 forks source link

opentelemetry-instrumentation-system-metrics: collecting fails on windows because of missing num_fds #2870

Closed jenshnielsen closed 1 day ago

jenshnielsen commented 1 month ago

Describe your environment

OS: Windows 11 Python version: Any but specifically 3.11 Package version: (e.g., 0.48b0) of opentelemetry-instrumentation-system-metrics

What happened?

Enabling system metrics with the default configuration result in errors of the form AttributeError: 'Process' object has no attribute 'num_fds' during metrics collection on windows

This metrics was implemented in #2652 which was first part of 0.480b of opentelemetry-instrumentation-system-metrics

Steps to Reproduce

from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader
from opentelemetry import metrics
exporter = ConsoleMetricExporter()
reader = PeriodicExportingMetricReader(exporter=exporter)
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)
from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor
SystemMetricsInstrumentor().instrument()

And wait for metrics to be collected and you will see an error as below

Expected Result

No errors during metrics collection. Either metric is off by default or implemented differently on window

Actual Result

Error during metrics collection

Callback failed for instrument process.open_file_descriptor.count.
Traceback (most recent call last):
  File "C:\Users\jenielse\Miniconda3\envs\myenv\Lib\site-packages\opentelemetry\sdk\metrics\_internal\instrument.py", line 137, in callback
    for api_measurement in callback(callback_options):
  File "C:\Users\jenielse\Miniconda3\envs\myenv\Lib\site-packages\opentelemetry\instrumentation\system_metrics\__init__.py", line 415, in _get_open_file_descriptors
    self._proc.num_fds(),
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'Process' object has no attribute 'num_fds'

Since psutils does not implement num_fds on windows

Additional context

No response

Would you like to implement a fix?

None

xrmx commented 1 month ago

Thanks for reporting, that means that we are not running tests for this instrumentation on windows I guess :sweat:

shijiadong2022 commented 1 month ago

Will a check of sys.platform be sufficient OR need to collect this metric on Windows?

jenshnielsen commented 1 month ago

As far as I am concerned skipping it is fine. I assumed but have not checked that psutil does not implement it on windows because there is no straightforward way to implement this.

shijiadong2022 commented 1 month ago

I am working on it and will submit a PR soon