Skip to content

Commit 30c0276

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

datadog_lambda/metric.py

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
55

6+
import numbers
67
import os
78
import time
89
import logging
@@ -55,6 +56,20 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
5556
Note that if the extension is present, it will override the DD_FLUSH_TO_LOG value
5657
and always use the layer to send metrics to the extension
5758
"""
59+
if not metric_name or not isinstance(metric_name, str):
60+
logger.warning(
61+
"Ignoring metric submission. Invalid metric name: %s", metric_name
62+
)
63+
return
64+
65+
if not isinstance(value, numbers.Number):
66+
logger.warning(
67+
"Ignoring metric submission for metric '%s' because the value is not numeric: %r",
68+
metric_name,
69+
value,
70+
)
71+
return
72+
5873
flush_to_logs = os.environ.get("DD_FLUSH_TO_LOG", "").lower() == "true"
5974
tags = [] if tags is None else list(tags)
6075
tags.append(dd_lambda_layer_tag)

0 commit comments

Comments
 (0)