11# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22# SPDX-License-Identifier: Apache-2.0
3- from typing import Dict , Optional
3+ from typing import Callable , Dict , Optional
44
55from typing_extensions import override
66
@@ -45,19 +45,29 @@ class AwsSpanMetricsProcessor(SpanProcessor):
4545 _generator : MetricAttributeGenerator
4646 _resource : Resource
4747
48+ _force_flush_function : Callable
49+
50+ # no op function to act as a default function in case forceFlushFunction was
51+ # not supplied to the the constructor.
52+ # pylint: disable=no-self-use
53+ def _no_op_function (self , timeout_millis : float = None ) -> bool :
54+ return True
55+
4856 def __init__ (
4957 self ,
5058 error_histogram : Histogram ,
5159 fault_histogram : Histogram ,
5260 latency_histogram : Histogram ,
5361 generator : MetricAttributeGenerator ,
5462 resource : Resource ,
63+ force_flush_function : Callable = _no_op_function ,
5564 ):
5665 self ._error_histogram = error_histogram
5766 self ._fault_histogram = fault_histogram
5867 self ._latency_histogram = latency_histogram
5968 self ._generator = generator
6069 self ._resource = resource
70+ self ._force_flush_function = force_flush_function
6171
6272 # pylint: disable=no-self-use
6373 @override
@@ -78,8 +88,8 @@ def shutdown(self) -> None:
7888
7989 # pylint: disable=no-self-use
8090 @override
81- def force_flush (self , timeout_millis : int = None ) -> bool :
82- return True
91+ def force_flush (self , timeout_millis : float = 10_000 ) -> bool :
92+ return self . _force_flush_function ( timeout_millis )
8393
8494 def _record_metrics (self , span : ReadableSpan , attributes : BoundedAttributes ) -> None :
8595 # Only record metrics if non-empty attributes are returned.
0 commit comments