From 767a1df39eb5f2e29b45dcc90ae16a3744e2aad0 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Mon, 10 Feb 2020 11:41:31 -0500 Subject: [PATCH 1/8] Enable log injection by default --- README.md | 2 +- datadog_lambda/wrapper.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87d87c4a..645468a7 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ If your Lambda function powers a performance-critical task (e.g., a consumer-fac - DD_FLUSH_TO_LOG -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). +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). Defaults to true. - DD_LOGS_INJECTION diff --git a/datadog_lambda/wrapper.py b/datadog_lambda/wrapper.py index f4230372..cc751e76 100644 --- a/datadog_lambda/wrapper.py +++ b/datadog_lambda/wrapper.py @@ -47,7 +47,9 @@ class _LambdaDecorator(object): def __init__(self, func): self.func = func self.flush_to_log = os.environ.get("DD_FLUSH_TO_LOG", "").lower() == "true" - self.logs_injection = os.environ.get("DD_LOGS_INJECTION", "").lower() == "true" + self.logs_injection = ( + os.environ.get("DD_LOGS_INJECTION", "true").lower() == "true" + ) # Inject trace correlation ids to logs if self.logs_injection: From cb67d287e5e874f5979c97db05cd9a9e337315ac Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Mon, 10 Feb 2020 11:43:31 -0500 Subject: [PATCH 2/8] Set version to 2.13 --- datadog_lambda/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog_lambda/__init__.py b/datadog_lambda/__init__.py index ba799966..eec8c359 100644 --- a/datadog_lambda/__init__.py +++ b/datadog_lambda/__init__.py @@ -1,6 +1,6 @@ # The minor version corresponds to the Lambda layer version. # E.g.,, version 0.5.0 gets packaged into layer version 5. -__version__ = "1.12.0" +__version__ = "2.13.0" import os From e5bc12261b5b9a86f1a6c4fcfef97766b2ccb1ad Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Mon, 10 Feb 2020 11:50:03 -0500 Subject: [PATCH 3/8] Update tests --- tests/test_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 12e87835..ec4b4a32 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -89,7 +89,7 @@ def lambda_handler(event, context): self.mock_wrapper_lambda_stats.flush.assert_called() self.mock_extract_dd_trace_context.assert_called_with(lambda_event) self.mock_set_correlation_ids.assert_called() - self.mock_inject_correlation_ids.assert_not_called() + self.mock_inject_correlation_ids.assert_called() self.mock_patch_all.assert_called() def test_datadog_lambda_wrapper_flush_to_log(self): From f470f31a942b73fea4213c8a985a2c5a152397e0 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Mon, 10 Feb 2020 11:51:55 -0500 Subject: [PATCH 4/8] Update README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 645468a7..bb56a0fd 100644 --- a/README.md +++ b/README.md @@ -235,10 +235,11 @@ If your Lambda function is triggered by API Gateway via [the non-proxy integrati If your Lambda function is deployed by the Serverless Framework, such a mapping template gets created by default. ## Log and Trace Correlations +By default, the Datadog trace id gets automatically injected into the logs for correlation, if using `console` or a logging library supported for [automatic](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=nodejs#automatic-trace-id-injection) trace id injection. -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). +See instructions for [manual](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=nodejs#manual-trace-id-injection) trace id injection, if using other logging libraries. If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. -If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. +Set the environment variable `DD_LOGS_INJECTION` to `false` to disable this feature. ```python from datadog_lambda.wrapper import datadog_lambda_wrapper From ef95da1c5a4c1bf814ff1ad2626b92f7c3214f9e Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Mon, 10 Feb 2020 13:01:34 -0500 Subject: [PATCH 5/8] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb56a0fd..c98bcff2 100644 --- a/README.md +++ b/README.md @@ -235,9 +235,9 @@ If your Lambda function is triggered by API Gateway via [the non-proxy integrati If your Lambda function is deployed by the Serverless Framework, such a mapping template gets created by default. ## Log and Trace Correlations -By default, the Datadog trace id gets automatically injected into the logs for correlation, if using `console` or a logging library supported for [automatic](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=nodejs#automatic-trace-id-injection) trace id injection. +By default, the Datadog trace id gets automatically injected into the logs for correlation, if using the AWS provided `LambdaLoggerHandler`. -See instructions for [manual](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=nodejs#manual-trace-id-injection) trace id injection, if using other logging libraries. If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. +If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. Set the environment variable `DD_LOGS_INJECTION` to `false` to disable this feature. From 27accd0aad163f86aa33680fdb25cd4164f07e98 Mon Sep 17 00:00:00 2001 From: Darcy Rayner <50632605+DarcyRaynerDD@users.noreply.github.com> Date: Mon, 10 Feb 2020 13:17:58 -0500 Subject: [PATCH 6/8] Update README.md Co-Authored-By: Tian Chu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c98bcff2..bcae0e3a 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ If your Lambda function is triggered by API Gateway via [the non-proxy integrati If your Lambda function is deployed by the Serverless Framework, such a mapping template gets created by default. ## Log and Trace Correlations -By default, the Datadog trace id gets automatically injected into the logs for correlation, if using the AWS provided `LambdaLoggerHandler`. +By default, the Datadog trace id gets automatically injected into the logs for correlation, if using the standard python `logging` library. If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. From 159150b93e18bedb46e860f5fd1aac02320cea58 Mon Sep 17 00:00:00 2001 From: Darcy Rayner <50632605+DarcyRaynerDD@users.noreply.github.com> Date: Mon, 10 Feb 2020 13:18:05 -0500 Subject: [PATCH 7/8] Update README.md Co-Authored-By: Tian Chu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bcae0e3a..7cb0fe5c 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ If your Lambda function powers a performance-critical task (e.g., a consumer-fac - DD_FLUSH_TO_LOG -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). Defaults to true. +Inject Datadog trace id into logs for [correlation](https://docs.datadoghq.com/tracing/connect_logs_and_traces/?tab=python). Defaults to true. - DD_LOGS_INJECTION From 00c02c3745aaef5189a591469e5fe38a799aff58 Mon Sep 17 00:00:00 2001 From: Tian Chu Date: Mon, 10 Feb 2020 13:19:51 -0500 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cb0fe5c..b777817e 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ If your Lambda function is deployed by the Serverless Framework, such a mapping ## Log and Trace Correlations By default, the Datadog trace id gets automatically injected into the logs for correlation, if using the standard python `logging` library. -If you use a custom logger handler to log in json, you can manually inject the ids using the helper function `get_correlation_ids`. +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). Set the environment variable `DD_LOGS_INJECTION` to `false` to disable this feature.