diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ae64c1531..a7baa168d72 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 +- Standardizing timeout calculation in measurement consumer collect to nanoseconds + ([#4074](https://github.com/open-telemetry/opentelemetry-python/pull/4074)) - optional scope attributes for logger creation ([#4035](https://github.com/open-telemetry/opentelemetry-python/pull/4035)) - optional scope attribute for tracer creation diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py index c5e81678dcb..4310061b823 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py @@ -100,18 +100,18 @@ def collect( metric_reader_storage = self._reader_storages[metric_reader] # for now, just use the defaults callback_options = CallbackOptions() - deadline_ns = time_ns() + timeout_millis * 10**6 + deadline_ns = time_ns() + (timeout_millis * 1e6) - default_timeout_millis = 10000 * 10**6 + default_timeout_ns = 10000 * 1e6 for async_instrument in self._async_instruments: remaining_time = deadline_ns - time_ns() - if remaining_time < default_timeout_millis: + if remaining_time < default_timeout_ns: callback_options = CallbackOptions( - timeout_millis=remaining_time + timeout_millis=remaining_time / 1e6 ) measurements = async_instrument.callback(callback_options) diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index 19c514c13e8..91a49955b70 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -182,5 +182,5 @@ def sleep_1(*args, **kwargs): self.assertLess( callback_options_time_call, - 10000 * 10**6, + 10000, )