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
2 changes: 2 additions & 0 deletions datadog_lambda/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
timestamp_ceiling = int(
(datetime.now() - timedelta(hours=4)).timestamp()
) # 4 hours ago
if isinstance(timestamp, datetime):
timestamp = int(timestamp.timestamp())
if timestamp_ceiling > timestamp:
logger.warning(
"Timestamp %s is older than 4 hours, not submitting metric %s",
Expand Down
13 changes: 13 additions & 0 deletions tests/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ def test_lambda_metric_timestamp_with_extension(self):
"test_timestamp", 1, timestamp=timestamp, tags=[dd_lambda_layer_tag]
)

@patch("datadog_lambda.metric.should_use_extension", True)
def test_lambda_metric_datetime_with_extension(self):
patcher = patch("datadog_lambda.metric.extension_thread_stats")
self.mock_metric_extension_thread_stats = patcher.start()
self.addCleanup(patcher.stop)

delta = timedelta(hours=5)
timestamp = datetime.now() - delta

lambda_metric("test_timestamp", 1, timestamp)
self.mock_metric_lambda_stats.distribution.assert_not_called()
self.mock_metric_extension_thread_stats.distribution.assert_not_called()

@patch("datadog_lambda.metric.should_use_extension", True)
def test_lambda_metric_invalid_timestamp_with_extension(self):
patcher = patch("datadog_lambda.metric.extension_thread_stats")
Expand Down