Skip to content

Commit e3c0a45

Browse files
authored
Only replace the logging formatter if it is a logging.Formatter (#155)
* Only replace the logging handler if the logging handler is using a logging.Formatter * Update README to mention that DD_LOGS_INJECTION only replaces the logger.Formatter in the LambdaLoggerHandler
1 parent c54d14d commit e3c0a45

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), you must set `DD_SITE`
6565

6666
### DD_LOGS_INJECTION
6767

68-
Inject Datadog trace id into logs for [correlation](https://docs.datadoghq.com/tracing/connect_logs_and_traces/python/). Defaults to `true`.
68+
Inject Datadog trace id into logs for [correlation](https://docs.datadoghq.com/tracing/connect_logs_and_traces/python/) if you are using a `logging.Formatter` in the default `LambdaLoggerHandler` by the Lambda runtime. Defaults to `true`.
6969

7070
### DD_LOG_LEVEL
7171

datadog_lambda/tracing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ def inject_correlation_ids():
336336
# Override the log format of the AWS provided LambdaLoggerHandler
337337
root_logger = logging.getLogger()
338338
for handler in root_logger.handlers:
339-
if handler.__class__.__name__ == "LambdaLoggerHandler":
339+
if (
340+
handler.__class__.__name__ == "LambdaLoggerHandler"
341+
and type(handler.formatter) == logging.Formatter
342+
):
340343
handler.setFormatter(
341344
logging.Formatter(
342345
"[%(levelname)s]\t%(asctime)s.%(msecs)dZ\t%(aws_request_id)s\t"

0 commit comments

Comments
 (0)