File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed
opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_internal Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -373,12 +373,35 @@ def __init__(
373
373
def force_flush (self , timeout_millis : float = 10_000 ) -> bool :
374
374
deadline_ns = _time_ns () + timeout_millis * 10 ** 6
375
375
376
+ metric_reader_error = {}
377
+
376
378
for metric_reader in self ._sdk_config .metric_readers :
377
379
current_ts = _time_ns ()
378
- if current_ts >= deadline_ns :
379
- raise Exception ("Timed out while flushing metric readers" )
380
- metric_reader .collect (
381
- timeout_millis = (deadline_ns - current_ts ) / 10 ** 6
380
+ try :
381
+ if current_ts >= deadline_ns :
382
+ raise Exception ("Timed out while flushing metric readers" )
383
+ metric_reader .collect (
384
+ timeout_millis = (deadline_ns - current_ts ) / 10 ** 6
385
+ )
386
+
387
+ # pylint: disable=broad-except
388
+ except Exception as error :
389
+
390
+ metric_reader_error [metric_reader ] = error
391
+
392
+ if metric_reader_error :
393
+
394
+ metric_reader_error_string = "\n " .join (
395
+ [
396
+ f"{ metric_reader .__class__ .__name__ } : { repr (error )} "
397
+ for metric_reader , error in metric_reader_error .items ()
398
+ ]
399
+ )
400
+
401
+ raise Exception (
402
+ "MeterProvider.force_flush failed because the following "
403
+ "metric readers failed during collect:\n "
404
+ f"{ metric_reader_error_string } "
382
405
)
383
406
return True
384
407
You can’t perform that action at this time.
0 commit comments