Skip to content

Commit dc320f8

Browse files
committed
Add logs_injection.
1 parent 18f49c2 commit dc320f8

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

datadog_lambda/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Config:
3232
enhanced_metrics_enabled = _get_env("DD_ENHANCED_METRICS", "true", as_bool)
3333
flush_in_thread = _get_env("DD_FLUSH_IN_THREAD", "false", as_bool)
3434
flush_to_log = _get_env("DD_FLUSH_TO_LOG", "false", as_bool)
35+
logs_injection = _get_env("DD_LOGS_INJECTION", "true", as_bool)
3536
function_name = _get_env("AWS_LAMBDA_FUNCTION_NAME")
3637
is_gov_region = _get_env("AWS_REGION", "", lambda x: x.startswith("us-gov-"))
3738
is_in_tests = _get_env("DD_INTEGRATION_TEST", "false", as_bool)

datadog_lambda/wrapper.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ def __init__(self, func):
157157
"""Executes when the wrapped function gets wrapped"""
158158
try:
159159
self.func = func
160-
self.logs_injection = (
161-
os.environ.get(DD_LOGS_INJECTION, "true").lower() == "true"
162-
)
163160
self.merge_xray_traces = (
164161
os.environ.get(DD_MERGE_XRAY_TRACES, "false").lower() == "true"
165162
)
@@ -213,7 +210,7 @@ def __init__(self, func):
213210
self.trace_extractor = getattr(extractor_module, extractor_name)
214211

215212
# Inject trace correlation ids to logs
216-
if self.logs_injection:
213+
if config.logs_injection:
217214
inject_correlation_ids()
218215

219216
# This prevents a breaking change in ddtrace v0.49 regarding the service name

tests/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ def set_env(key, value):
2727
("DD_FLUSH_TO_LOG", "flush_to_log", "1", True), # CHANGED
2828
("DD_FLUSH_TO_LOG", "flush_to_log", "0", False),
2929
("DD_FLUSH_TO_LOG", "flush_to_log", "purple", False),
30+
("DD_LOGS_INJECTION", "logs_injection", None, True),
31+
("DD_LOGS_INJECTION", "logs_injection", "", False),
32+
("DD_LOGS_INJECTION", "logs_injection", "true", True),
33+
("DD_LOGS_INJECTION", "logs_injection", "TRUE", True),
34+
("DD_LOGS_INJECTION", "logs_injection", "false", False),
35+
("DD_LOGS_INJECTION", "logs_injection", "FALSE", False),
36+
("DD_LOGS_INJECTION", "logs_injection", "1", True), # CHANGED
37+
("DD_LOGS_INJECTION", "logs_injection", "0", False),
38+
("DD_LOGS_INJECTION", "logs_injection", "purple", False),
3039
("DD_TRACE_ENABLED", "trace_enabled", None, True),
3140
("DD_TRACE_ENABLED", "trace_enabled", "", False),
3241
("DD_TRACE_ENABLED", "trace_enabled", "true", True),

0 commit comments

Comments
 (0)