Skip to content

Commit

Permalink
Standardizing timeout calculation in measurement consumer collect to …
Browse files Browse the repository at this point in the history
…nanoseconds (#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 <9735060+emdneto@users.noreply.github.com>
  • Loading branch information
mdcg and emdneto authored Jul 23, 2024
1 parent be02f98 commit 3f95781
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ def sleep_1(*args, **kwargs):

self.assertLess(
callback_options_time_call,
10000 * 10**6,
10000,
)

0 comments on commit 3f95781

Please sign in to comment.