Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -45,19 +45,29 @@ 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,
fault_histogram: Histogram,
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
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Loading