Skip to content

Commit 2c2162f

Browse files
committed
Add profiling_enabled.
1 parent b2f04b5 commit 2c2162f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

datadog_lambda/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Config:
5858
merge_xray_traces = _get_env("DD_MERGE_XRAY_TRACES", "false", as_bool)
5959
trace_extractor = _get_env("DD_TRACE_EXTRACTOR")
6060
capture_payload_max_depth = _get_env("DD_CAPTURE_PAYLOAD_MAX_DEPTH", 10, int)
61+
profiling_enabled = _get_env("DD_PROFILING_ENABLED", "false", as_bool)
6162

6263
@property
6364
def fips_mode_enabled(self):

datadog_lambda/wrapper.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
extract_http_status_code_tag,
4646
)
4747

48-
profiling_env_var = os.environ.get("DD_PROFILING_ENABLED", "false").lower() == "true"
49-
if profiling_env_var:
48+
if config.profiling_enabled:
5049
from ddtrace.profiling import profiler
5150

5251
llmobs_env_var = os.environ.get("DD_LLMOBS_ENABLED", "false").lower() in ("true", "1")
@@ -181,7 +180,7 @@ def __init__(self, func):
181180
except Exception:
182181
logger.debug(f"Malformatted for env {DD_COLD_START_TRACE_SKIP_LIB}")
183182
self.response = None
184-
if profiling_env_var:
183+
if config.profiling_enabled:
185184
self.prof = profiler.Profiler(env=env_env_var, service=config.service)
186185
if config.trace_extractor:
187186
extractor_parts = config.trace_extractor.rsplit(".", 1)
@@ -311,7 +310,7 @@ def _before(self, event, context):
311310
)
312311
else:
313312
set_correlation_ids()
314-
if profiling_env_var and is_new_sandbox():
313+
if config.profiling_enabled and is_new_sandbox():
315314
self.prof.start(stop_on_exit=False, profile_children=True)
316315
logger.debug("datadog_lambda_wrapper _before() done")
317316
except Exception as e:

tests/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ def set_env(key, value):
137137
("DD_CAPTURE_PAYLOAD_MAX_DEPTH", "capture_payload_max_depth", "2.5", 10),
138138
("DD_CAPTURE_PAYLOAD_MAX_DEPTH", "capture_payload_max_depth", "-1", -1),
139139
("DD_CAPTURE_PAYLOAD_MAX_DEPTH", "capture_payload_max_depth", "purple", 10),
140+
("DD_PROFILING_ENABLED", "profiling_enabled", None, False),
141+
("DD_PROFILING_ENABLED", "profiling_enabled", "", False),
142+
("DD_PROFILING_ENABLED", "profiling_enabled", "true", True),
143+
("DD_PROFILING_ENABLED", "profiling_enabled", "TRUE", True),
144+
("DD_PROFILING_ENABLED", "profiling_enabled", "false", False),
145+
("DD_PROFILING_ENABLED", "profiling_enabled", "FALSE", False),
146+
("DD_PROFILING_ENABLED", "profiling_enabled", "1", True), # CHANGED
147+
("DD_PROFILING_ENABLED", "profiling_enabled", "0", False),
148+
("DD_PROFILING_ENABLED", "profiling_enabled", "purple", False),
140149
)
141150

142151

0 commit comments

Comments
 (0)