From 3e8249ae789497a33fa8639fabff809e82a6b5aa Mon Sep 17 00:00:00 2001 From: "chris.agocs" Date: Fri, 23 Jul 2021 15:20:28 -0400 Subject: [PATCH 1/2] Only replace the logging handler if the logging handler is using a logging.Formatter --- datadog_lambda/tracing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datadog_lambda/tracing.py b/datadog_lambda/tracing.py index 49e1d05f..b97c2d8f 100644 --- a/datadog_lambda/tracing.py +++ b/datadog_lambda/tracing.py @@ -336,7 +336,10 @@ def inject_correlation_ids(): # Override the log format of the AWS provided LambdaLoggerHandler root_logger = logging.getLogger() for handler in root_logger.handlers: - if handler.__class__.__name__ == "LambdaLoggerHandler": + if ( + handler.__class__.__name__ == "LambdaLoggerHandler" + and type(handler.formatter) == logging.Formatter + ): handler.setFormatter( logging.Formatter( "[%(levelname)s]\t%(asctime)s.%(msecs)dZ\t%(aws_request_id)s\t" From d387c2afb399e222239b5f9b8ce0a4b4fa6f6bae Mon Sep 17 00:00:00 2001 From: "chris.agocs" Date: Fri, 23 Jul 2021 16:56:28 -0400 Subject: [PATCH 2/2] Update README to mention that DD_LOGS_INJECTION only replaces the logger.Formatter in the LambdaLoggerHandler --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 807b7df9..0ba89f2e 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), you must set `DD_SITE` ### DD_LOGS_INJECTION -Inject Datadog trace id into logs for [correlation](https://docs.datadoghq.com/tracing/connect_logs_and_traces/python/). Defaults to `true`. +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`. ### DD_LOG_LEVEL