Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
self.env_patcher.start()

def tearDown(self):
del os.environ["AWS_REGION"]
self.env_patcher.stop()

@patch("datadog_lambda.config.Config.fips_mode_enabled", True)
@patch("botocore.session.Session.create_client")
Expand Down Expand Up @@ -172,7 +172,6 @@ def test_no_fips_for_standard_regions(self, mock_boto3_client):
mock_client.get_secret_value.return_value = {"SecretString": "test-api-key"}
mock_boto3_client.return_value = mock_client

os.environ.clear()
os.environ["AWS_REGION"] = "us-west-2"
os.environ["DD_API_KEY_SECRET_ARN"] = (
"arn:aws:secretsmanager:us-west-2:1234567890:secret:key-name-123ABC"
Expand Down
15 changes: 8 additions & 7 deletions tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def lambda_handler(event, context):
self.mock_inject_correlation_ids.assert_called()

def test_datadog_lambda_wrapper_flush_to_log(self):
self.addCleanup(os.environ.pop, "DD_FLUSH_TO_LOG", None)
os.environ["DD_FLUSH_TO_LOG"] = "True"

@wrapper.datadog_lambda_wrapper
Expand All @@ -124,8 +125,6 @@ def lambda_handler(event, context):

self.mock_threadstats_flush_distributions.assert_not_called()

del os.environ["DD_FLUSH_TO_LOG"]

def test_datadog_lambda_wrapper_flush_in_thread(self):
# force ThreadStats to flush in thread
import datadog_lambda.metric as metric_module
Expand Down Expand Up @@ -183,6 +182,7 @@ def lambda_handler(event, context):

@patch("datadog_lambda.config.Config.trace_enabled", False)
def test_datadog_lambda_wrapper_inject_correlation_ids(self):
self.addCleanup(os.environ.pop, "DD_LOGS_INJECTION", None)
os.environ["DD_LOGS_INJECTION"] = "True"

@wrapper.datadog_lambda_wrapper
Expand All @@ -194,8 +194,6 @@ def lambda_handler(event, context):
self.mock_set_correlation_ids.assert_called()
self.mock_inject_correlation_ids.assert_called()

del os.environ["DD_LOGS_INJECTION"]

def test_invocations_metric(self):
@wrapper.datadog_lambda_wrapper
def lambda_handler(event, context):
Expand Down Expand Up @@ -484,6 +482,7 @@ def lambda_handler(event, context):

def test_dd_requests_service_name_default(self):
# TODO(astuyve) this is now set by CI, so we need to null it out for this case
self.addCleanup(os.environ.pop, "DD_SERVICE", None)
os.environ["DD_SERVICE"] = "aws.lambda"

@wrapper.datadog_lambda_wrapper
Expand All @@ -493,14 +492,14 @@ def lambda_handler(event, context):
self.assertEqual(os.environ.get("DD_REQUESTS_SERVICE_NAME"), "aws.lambda")

def test_dd_requests_service_name_set(self):
self.addCleanup(os.environ.pop, "DD_SERVICE", None)
os.environ["DD_SERVICE"] = "myAwesomeService"

@wrapper.datadog_lambda_wrapper
def lambda_handler(event, context):
pass

self.assertEqual(os.environ.get("DD_REQUESTS_SERVICE_NAME"), "myAwesomeService")
del os.environ["DD_SERVICE"]

@patch("datadog_lambda.config.Config.make_inferred_span", False)
def test_encode_authorizer_span(self):
Expand Down Expand Up @@ -563,12 +562,13 @@ class TestLambdaWrapperWithTraceContext(unittest.TestCase):
f"Root={xray_root};Parent={xray_parent};Sampled=1;Lineage=c6c5b1b9:0"
)

@patch(
"os.environ",
@patch.dict(
os.environ,
{
"AWS_XRAY_DAEMON_ADDRESS": xray_daemon_envvar,
"_X_AMZN_TRACE_ID": xray_trace_envvar,
},
clear=True,
)
def test_event_bridge_sqs_payload(self):
reset_xray_connection()
Expand Down Expand Up @@ -782,6 +782,7 @@ def lambda_handler(event, context):
lambda_handler(self.api_gateway_request, get_mock_context())

def test_no_blocking_appsec_disabled(self):
self.addCleanup(os.environ.pop, "DD_APPSEC_ENABLED", None)
os.environ["DD_APPSEC_ENABLED"] = "false"

importlib.reload(wrapper)
Expand Down
Loading