Skip to content

Commit 7f4cd7a

Browse files
feat: disable direct metric submission in govcloud
1 parent 2320c0a commit 7f4cd7a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

datadog_lambda/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import logging
33

4+
from datadog_lambda.aws import current_region, running_in_gov_region
5+
46
logger = logging.getLogger(__name__)
57
KMS_ENCRYPTION_CONTEXT_KEY = "LambdaFunctionName"
68
api_key = None
@@ -62,8 +64,8 @@ def get_api_key() -> str:
6264
DD_KMS_API_KEY = os.environ.get("DD_KMS_API_KEY", "")
6365
DD_API_KEY = os.environ.get("DD_API_KEY", os.environ.get("DATADOG_API_KEY", ""))
6466

65-
LAMBDA_REGION = os.environ.get("AWS_REGION", "")
66-
is_gov_region = LAMBDA_REGION.startswith("us-gov-")
67+
LAMBDA_REGION = current_region()
68+
is_gov_region = running_in_gov_region()
6769
if is_gov_region:
6870
logger.debug(
6971
"Govcloud region detected. Using FIPs endpoints for secrets management."

datadog_lambda/aws.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
4+
def current_region() -> str:
5+
return os.environ.get("AWS_REGION", "")
6+
7+
8+
def running_in_gov_region() -> bool:
9+
return current_region().startswith("us-gov-")

datadog_lambda/metric.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from datadog_lambda.extension import should_use_extension
1313
from datadog_lambda.tags import get_enhanced_metrics_tags, dd_lambda_layer_tag
14+
from datadog_lambda.aws import running_in_gov_region
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -76,6 +77,18 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
7677
tags.append(dd_lambda_layer_tag)
7778

7879
if should_use_extension and timestamp is not None:
80+
if running_in_gov_region():
81+
# Metrics with timestamps get shipped directly to datadog instead
82+
# of going to the agent. We cannot guarantee from our side that
83+
# this will be done in a FIPS-compliant way, so we disable this
84+
# feature for now. We may revisit it in the future.
85+
logger.warning(
86+
"Ignoring metric submission for metric '%s' because we cannot guarantee "
87+
"FIPS-compliance for metrics submitted directly to Datadog.",
88+
metric_name,
89+
)
90+
return
91+
7992
# The extension does not support timestamps for distributions so we create a
8093
# a thread stats writer to submit metrics with timestamps to the API
8194
timestamp_ceiling = int(

0 commit comments

Comments
 (0)