Skip to content

Commit 3f95781

Browse files
mdcgemdneto
andauthored
Standardizing timeout calculation in measurement consumer collect to nanoseconds (open-telemetry#4074)
* fix: standardizing timeout calculation in measurement consumer collect to nanoseconds * style: apply formatter * update CHANGELOG.md * typo: update CHANGELOG.md * Update opentelemetry-sdk/tests/metrics/test_measurement_consumer.py * fix: removing unnecessary test --------- Co-authored-by: Emídio Neto <[email protected]>
1 parent be02f98 commit 3f95781

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Standardizing timeout calculation in measurement consumer collect to nanoseconds
11+
([#4074](https://github.com/open-telemetry/opentelemetry-python/pull/4074))
1012
- optional scope attributes for logger creation
1113
([#4035](https://github.com/open-telemetry/opentelemetry-python/pull/4035))
1214
- optional scope attribute for tracer creation

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ def collect(
100100
metric_reader_storage = self._reader_storages[metric_reader]
101101
# for now, just use the defaults
102102
callback_options = CallbackOptions()
103-
deadline_ns = time_ns() + timeout_millis * 10**6
103+
deadline_ns = time_ns() + (timeout_millis * 1e6)
104104

105-
default_timeout_millis = 10000 * 10**6
105+
default_timeout_ns = 10000 * 1e6
106106

107107
for async_instrument in self._async_instruments:
108108

109109
remaining_time = deadline_ns - time_ns()
110110

111-
if remaining_time < default_timeout_millis:
111+
if remaining_time < default_timeout_ns:
112112

113113
callback_options = CallbackOptions(
114-
timeout_millis=remaining_time
114+
timeout_millis=remaining_time / 1e6
115115
)
116116

117117
measurements = async_instrument.callback(callback_options)

opentelemetry-sdk/tests/metrics/test_measurement_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,5 @@ def sleep_1(*args, **kwargs):
182182

183183
self.assertLess(
184184
callback_options_time_call,
185-
10000 * 10**6,
185+
10000,
186186
)

0 commit comments

Comments
 (0)