diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py index 78346748c..ee7e86be7 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py @@ -1,6 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -from typing import Dict, Optional +from typing import Callable, Dict, Optional from typing_extensions import override @@ -45,6 +45,14 @@ class AwsSpanMetricsProcessor(SpanProcessor): _generator: MetricAttributeGenerator _resource: Resource + _force_flush_function: Callable + + # no op function to act as a default function in case forceFlushFunction was + # not supplied to the the constructor. + # pylint: disable=no-self-use + def _no_op_function(self, timeout_millis: float = None) -> bool: + return True + def __init__( self, error_histogram: Histogram, @@ -52,12 +60,14 @@ def __init__( latency_histogram: Histogram, generator: MetricAttributeGenerator, resource: Resource, + force_flush_function: Callable = _no_op_function, ): self._error_histogram = error_histogram self._fault_histogram = fault_histogram self._latency_histogram = latency_histogram self._generator = generator self._resource = resource + self._force_flush_function = force_flush_function # pylint: disable=no-self-use @override @@ -78,8 +88,8 @@ def shutdown(self) -> None: # pylint: disable=no-self-use @override - def force_flush(self, timeout_millis: int = None) -> bool: - return True + def force_flush(self, timeout_millis: float = 10_000) -> bool: + return self._force_flush_function(timeout_millis) def _record_metrics(self, span: ReadableSpan, attributes: BoundedAttributes) -> None: # Only record metrics if non-empty attributes are returned. diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py index 794fc0b84..686e42f0d 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py @@ -63,5 +63,10 @@ def build(self) -> AwsSpanMetricsProcessor: latency_histogram.name = _LATENCY return AwsSpanMetricsProcessor( - error_histogram, fault_histogram, latency_histogram, self._generator, self._resource + error_histogram, + fault_histogram, + latency_histogram, + self._generator, + self._resource, + self._meter_provider.force_flush, )