Skip to content

Commit 66efacd

Browse files
committed
log warning and skip when metric name or value is invalid
1 parent e40f4a8 commit 66efacd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

datadog_lambda/metric.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# under the Apache License Version 2.0.
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
5-
5+
import numbers
66
import os
77
import time
88
import logging
@@ -55,6 +55,20 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
5555
Note that if the extension is present, it will override the DD_FLUSH_TO_LOG value
5656
and always use the layer to send metrics to the extension
5757
"""
58+
if not metric_name or not isinstance(metric_name, str):
59+
logger.warning(
60+
"Ignoring metric submission. Invalid metric name: %s", metric_name
61+
)
62+
return
63+
64+
if not isinstance(value, numbers.Number):
65+
logger.warning(
66+
"Ignoring metric submission for metric '%s' because the value is not numeric: %r",
67+
metric_name,
68+
value,
69+
)
70+
return
71+
5872
flush_to_logs = os.environ.get("DD_FLUSH_TO_LOG", "").lower() == "true"
5973
tags = [] if tags is None else list(tags)
6074
tags.append(dd_lambda_layer_tag)

0 commit comments

Comments
 (0)