|
23 | 23 | from sys import stdout |
24 | 24 | from threading import Event, Lock, RLock, Thread |
25 | 25 | from time import perf_counter, time_ns |
26 | | -from typing import IO, Callable, Iterable, Optional |
| 26 | +from typing import IO, Callable, Iterable |
27 | 27 |
|
28 | 28 | from typing_extensions import final |
29 | 29 |
|
@@ -336,7 +336,7 @@ def __init__( |
336 | 336 | ) |
337 | 337 |
|
338 | 338 | @final |
339 | | - def collect(self, timeout_millis: float = 10_000) -> Optional[bool]: |
| 339 | + def collect(self, timeout_millis: float = 10_000) -> bool | None: |
340 | 340 | """Collects the metrics from the internal SDK state and |
341 | 341 | invokes the `_receive_metrics` with the collection. |
342 | 342 |
|
@@ -387,7 +387,7 @@ def _receive_metrics( |
387 | 387 | metrics_data: MetricsData, |
388 | 388 | timeout_millis: float = 10_000, |
389 | 389 | **kwargs, |
390 | | - ) -> bool: |
| 390 | + ) -> bool | None: |
391 | 391 | """Called by `MetricReader.collect` when it receives a batch of metrics. |
392 | 392 |
|
393 | 393 | Subclasses must return ``True`` on success and ``False`` on failure. |
@@ -445,7 +445,7 @@ def __init__( |
445 | 445 |
|
446 | 446 | def get_metrics_data( |
447 | 447 | self, |
448 | | - ) -> Optional[MetricsData]: |
| 448 | + ) -> MetricsData | None: |
449 | 449 | """Reads and returns current metrics from the SDK""" |
450 | 450 | with self._lock: |
451 | 451 | self.collect() |
@@ -480,8 +480,8 @@ class PeriodicExportingMetricReader(MetricReader): |
480 | 480 | def __init__( |
481 | 481 | self, |
482 | 482 | exporter: MetricExporter, |
483 | | - export_interval_millis: Optional[float] = None, |
484 | | - export_timeout_millis: Optional[float] = None, |
| 483 | + export_interval_millis: float | None = None, |
| 484 | + export_timeout_millis: float | None = None, |
485 | 485 | ) -> None: |
486 | 486 | # PeriodicExportingMetricReader defers to exporter for configuration |
487 | 487 | super().__init__( |
@@ -608,6 +608,6 @@ def _shutdown(): |
608 | 608 | self._exporter.shutdown(timeout=(deadline_ns - time_ns()) / 10**6) |
609 | 609 |
|
610 | 610 | def force_flush(self, timeout_millis: float = 10_000) -> bool: |
611 | | - collect_ok = super().force_flush(timeout_millis=timeout_millis) |
612 | | - exporter_ok = self._exporter.force_flush(timeout_millis=timeout_millis) |
613 | | - return collect_ok and exporter_ok |
| 611 | + if not super().force_flush(timeout_millis=timeout_millis): |
| 612 | + return False |
| 613 | + return self._exporter.force_flush(timeout_millis=timeout_millis) |
0 commit comments