Skip to content

Commit 863fa9e

Browse files
committed
Add local_test.
1 parent 0e35ee1 commit 863fa9e

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

datadog_lambda/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class Config:
6868
llmobs_enabled = _get_env("DD_LLMOBS_ENABLED", "false", as_bool)
6969
exception_replay_enabled = _get_env("DD_EXCEPTION_REPLAY_ENABLED", "false", as_bool)
7070

71+
local_test = _get_env("DD_LOCAL_TEST", "false", as_bool)
72+
7173
@property
7274
def fips_mode_enabled(self):
7375
if not hasattr(self, "_config_fips_mode_enabled"):

datadog_lambda/wrapper.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
logger = logging.getLogger(__name__)
6060

61-
DD_LOCAL_TEST = "DD_LOCAL_TEST"
6261
DD_TRACE_MANAGED_SERVICES = "DD_TRACE_MANAGED_SERVICES"
6362
DD_ENCODE_AUTHORIZER_CONTEXT = "DD_ENCODE_AUTHORIZER_CONTEXT"
6463
DD_DECODE_AUTHORIZER_CONTEXT = "DD_DECODE_AUTHORIZER_CONTEXT"
@@ -70,16 +69,6 @@
7069
DD_DATA_STREAMS_ENABLED = "DD_DATA_STREAMS_ENABLED"
7170

7271

73-
def get_env_as_int(env_key, default_value: int) -> int:
74-
try:
75-
return int(os.environ.get(env_key, default_value))
76-
except Exception as e:
77-
logger.warn(
78-
f"Failed to parse {env_key} as int. Using default value: {default_value}. Error: {e}"
79-
)
80-
return default_value
81-
82-
8372
init_timestamp_ns = time_ns()
8473

8574
"""
@@ -153,9 +142,6 @@ def __init__(self, func):
153142
self.cold_start_tracing = depends_on_dd_tracing_enabled(
154143
os.environ.get(DD_COLD_START_TRACING, "true").lower() == "true"
155144
)
156-
self.min_cold_start_trace_duration = get_env_as_int(
157-
DD_MIN_COLD_START_DURATION, 3
158-
)
159145
self.data_streams_enabled = (
160146
os.environ.get(DD_DATA_STREAMS_ENABLED, "false").lower() == "true"
161147
)
@@ -368,7 +354,7 @@ def _after(self, event, context):
368354
from datadog_lambda.metric import flush_stats
369355

370356
flush_stats(context)
371-
if should_use_extension and self.local_testing_mode:
357+
if should_use_extension and config.local_test:
372358
# when testing locally, the extension does not know when an
373359
# invocation completes because it does not have access to the
374360
# logs api

tests/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ def set_env(key, value):
183183
("DD_MIN_COLD_START_DURATION", "min_cold_start_trace_duration", "2.5", 3),
184184
("DD_MIN_COLD_START_DURATION", "min_cold_start_trace_duration", "-1", -1),
185185
("DD_MIN_COLD_START_DURATION", "min_cold_start_trace_duration", "purple", 3),
186+
("DD_LOCAL_TEST", "local_test", None, False),
187+
("DD_LOCAL_TEST", "local_test", "", False),
188+
("DD_LOCAL_TEST", "local_test", "true", True),
189+
("DD_LOCAL_TEST", "local_test", "TRUE", True),
190+
("DD_LOCAL_TEST", "local_test", "false", False),
191+
("DD_LOCAL_TEST", "local_test", "FALSE", False),
192+
("DD_LOCAL_TEST", "local_test", "1", True), # CHANGED
193+
("DD_LOCAL_TEST", "local_test", "0", False),
194+
("DD_LOCAL_TEST", "local_test", "purple", False),
186195
)
187196

188197

0 commit comments

Comments
 (0)