Skip to content

Commit eeb1d02

Browse files
Merge pull request #44 from DataDog/darcy.rayner/set-log-injection-default
Enable log trace context injection by default
2 parents 3e676f4 + 00c02c3 commit eeb1d02

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ If your Lambda function powers a performance-critical task (e.g., a consumer-fac
8585

8686
- DD_FLUSH_TO_LOG
8787

88-
To connect logs and traces, set the environment variable below to `True`. The default format of the AWS provided `LambdaLoggerHandler` will be overridden to inject `dd.trace_id` and `dd.span_id`. The default Datadog lambda log integration pipeline will automatically parse them and map the `dd.trace_id` into the reserved [trace_id attribute](https://docs.datadoghq.com/logs/processing/#trace-id-attribute).
88+
Inject Datadog trace id into logs for [correlation](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=python). Defaults to true.
8989

9090
- DD_LOGS_INJECTION
9191

@@ -235,10 +235,11 @@ If your Lambda function is triggered by API Gateway via [the non-proxy integrati
235235
If your Lambda function is deployed by the Serverless Framework, such a mapping template gets created by default.
236236

237237
## Log and Trace Correlations
238+
By default, the Datadog trace id gets automatically injected into the logs for correlation, if using the standard python `logging` library.
238239

239-
To connect logs and traces, set the environment variable `DD_LOGS_INJECTION` to `True`. The log format of the AWS provided `LambdaLoggerHandler` will be overridden to inject `dd.trace_id` and `dd.span_id`. The default Datadog lambda log integration pipeline will automatically parse them and map the `dd.trace_id` into the reserved attribute [trace_id](https://docs.datadoghq.com/logs/processing/#trace-id-attribute).
240+
If you use a custom logger handler to log in json, you can inject the ids using the helper function `get_correlation_ids` [manually](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=python#manual-trace-id-injection).
240241

241-
If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`.
242+
Set the environment variable `DD_LOGS_INJECTION` to `false` to disable this feature.
242243

243244
```python
244245
from datadog_lambda.wrapper import datadog_lambda_wrapper

datadog_lambda/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The minor version corresponds to the Lambda layer version.
22
# E.g.,, version 0.5.0 gets packaged into layer version 5.
3-
__version__ = "1.12.0"
3+
__version__ = "2.13.0"
44

55

66
import os

datadog_lambda/wrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class _LambdaDecorator(object):
4747
def __init__(self, func):
4848
self.func = func
4949
self.flush_to_log = os.environ.get("DD_FLUSH_TO_LOG", "").lower() == "true"
50-
self.logs_injection = os.environ.get("DD_LOGS_INJECTION", "").lower() == "true"
50+
self.logs_injection = (
51+
os.environ.get("DD_LOGS_INJECTION", "true").lower() == "true"
52+
)
5153

5254
# Inject trace correlation ids to logs
5355
if self.logs_injection:

tests/test_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def lambda_handler(event, context):
8989
self.mock_wrapper_lambda_stats.flush.assert_called()
9090
self.mock_extract_dd_trace_context.assert_called_with(lambda_event)
9191
self.mock_set_correlation_ids.assert_called()
92-
self.mock_inject_correlation_ids.assert_not_called()
92+
self.mock_inject_correlation_ids.assert_called()
9393
self.mock_patch_all.assert_called()
9494

9595
def test_datadog_lambda_wrapper_flush_to_log(self):

0 commit comments

Comments
 (0)