From dd56e7f0b364d4540365e2ddacd34b2fb16b7717 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 19 Apr 2022 09:46:46 -0700 Subject: [PATCH] Continue processing async instruments if callback fails (#2614) --- CHANGELOG.md | 2 ++ .../src/opentelemetry/sdk/_metrics/instrument.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecba0eb2396..00afde11a11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.0-0.30b0...HEAD) +- Fix unhandled callback exceptions on async instruments + ([#2614](https://github.com/open-telemetry/opentelemetry-python/pull/2614)) - Rename `DefaultCounter`, `DefaultHistogram`, `DefaultObservableCounter`, `DefaultObservableGauge`, `DefaultObservableUpDownCounter`, `DefaultUpDownCounter` instruments to `NoOpCounter`, `NoOpHistogram`, `NoOpObservableCounter`, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py index c6e6e4c273b..260a9a77670 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py @@ -97,6 +97,10 @@ def callback(self) -> Iterable[Measurement]: ) except StopIteration: pass + except Exception: # pylint: disable=broad-except + _logger.exception( + "Callback failed for instrument %s.", self.name + ) class Counter(_Synchronous, APICounter):