Skip to content

Fix issue when metrics are not available#1207

Merged
codeboten merged 3 commits intoopen-telemetry:masterfrom
codeboten:fix-system-metrics
Oct 6, 2020
Merged

Fix issue when metrics are not available#1207
codeboten merged 3 commits intoopen-telemetry:masterfrom
codeboten:fix-system-metrics

Conversation

@codeboten
Copy link
Contributor

@codeboten codeboten commented Oct 6, 2020

Description

Not all configured metrics are available on all operating systems, added a hasattr call before calling the observer.

Fixes #1206

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Ran the instrumentation manually again after the change, error messages were gone.

Checklist:

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

Alex Boten added 2 commits October 5, 2020 20:55
Not all configured metrics are available on all operating
systems, added a hasattr call before calling the observer.
@codeboten codeboten requested a review from a team October 6, 2020 04:04
observer.observe(
getattr(times, metric), self._system_cpu_time_labels
)
if hasattr(times, metric):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about getattr here followed by a check for None? Would save one attribute lookup if/when on hotpath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good optimization, I thought about it but then I remembered the default interval for this instrumentation was to collect metrics every 30 seconds. Can definitely be improved when it becomes an issue

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious which operating system did not have these metrics?

@codeboten
Copy link
Contributor Author

Curious which operating system did not have these metrics?

The bug has more details regarding which metrics, but MacOS had a few metrics unavailable, so I just added a check for hasattr everywhere.

@codeboten codeboten merged commit f9218ca into open-telemetry:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System Metrics instrumentation shows Exception messages

3 participants