Skip to content

Commit 610e85a

Browse files
committed
Add local_test.
1 parent 302d472 commit 610e85a

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

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
@@ -56,7 +56,6 @@
5656

5757
logger = logging.getLogger(__name__)
5858

59-
DD_LOCAL_TEST = "DD_LOCAL_TEST"
6059
DD_TRACE_MANAGED_SERVICES = "DD_TRACE_MANAGED_SERVICES"
6160
DD_ENCODE_AUTHORIZER_CONTEXT = "DD_ENCODE_AUTHORIZER_CONTEXT"
6261
DD_DECODE_AUTHORIZER_CONTEXT = "DD_DECODE_AUTHORIZER_CONTEXT"
@@ -67,16 +66,6 @@
6766
DD_ENV = "DD_ENV"
6867

6968

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

8271
"""
@@ -150,9 +139,6 @@ def __init__(self, func):
150139
self.cold_start_tracing = depends_on_dd_tracing_enabled(
151140
os.environ.get(DD_COLD_START_TRACING, "true").lower() == "true"
152141
)
153-
self.local_testing_mode = os.environ.get(
154-
DD_LOCAL_TEST, "false"
155-
).lower() in ("true", "1")
156142
self.cold_start_trace_skip_lib = [
157143
"ddtrace.internal.compat",
158144
"ddtrace.filters",
@@ -357,7 +343,7 @@ def _after(self, event, context):
357343
from datadog_lambda.metric import flush_stats
358344

359345
flush_stats(context)
360-
if should_use_extension and self.local_testing_mode:
346+
if should_use_extension and config.local_test:
361347
# when testing locally, the extension does not know when an
362348
# invocation completes because it does not have access to the
363349
# 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)