Skip to content

Commit 5c81289

Browse files
committed
Add profiling_enabled.
1 parent 09adc0f commit 5c81289

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

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
@@ -46,8 +46,7 @@
4646
extract_http_status_code_tag,
4747
)
4848

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

5352
llmobs_env_var = os.environ.get("DD_LLMOBS_ENABLED", "false").lower() in ("true", "1")
@@ -187,7 +186,7 @@ def __init__(self, func):
187186
except Exception:
188187
logger.debug(f"Malformatted for env {DD_COLD_START_TRACE_SKIP_LIB}")
189188
self.response = None
190-
if profiling_env_var:
189+
if config.profiling_enabled:
191190
self.prof = profiler.Profiler(env=env_env_var, service=config.service)
192191
if config.trace_extractor:
193192
extractor_parts = config.trace_extractor.rsplit(".", 1)
@@ -319,7 +318,7 @@ def _before(self, event, context):
319318
)
320319
else:
321320
set_correlation_ids()
322-
if profiling_env_var and is_new_sandbox():
321+
if config.profiling_enabled and is_new_sandbox():
323322
self.prof.start(stop_on_exit=False, profile_children=True)
324323
logger.debug("datadog_lambda_wrapper _before() done")
325324
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)