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 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"