From b1305b81fcac93d15ed13b1bcfe86a29e6d7d239 Mon Sep 17 00:00:00 2001 From: Samuel Murillo Date: Tue, 3 Dec 2019 15:46:22 -0300 Subject: [PATCH 1/3] Allow kwargs on lambda handlers --- datadog_lambda/wrapper.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/datadog_lambda/wrapper.py b/datadog_lambda/wrapper.py index 99678ffa..683b6e91 100644 --- a/datadog_lambda/wrapper.py +++ b/datadog_lambda/wrapper.py @@ -57,9 +57,8 @@ def __init__(self, func): patch_all() logger.debug("datadog_lambda_wrapper initialized") - def _before(self, event, context): + def _before(self, event, context, **kwargs): set_cold_start() - try: submit_invocations_metric(context) # Extract Datadog trace context from incoming requests @@ -70,22 +69,22 @@ def _before(self, event, context): except Exception: traceback.print_exc() - def _after(self, event, context): + def _after(self, event, context, **kwargs): try: if not self.flush_to_log: lambda_stats.flush(float("inf")) except Exception: traceback.print_exc() - def __call__(self, event, context): - self._before(event, context) + def __call__(self, event, context, **kwargs): + self._before(event, context, **kwargs) try: - return self.func(event, context) + return self.func(event, context, **kwargs) except Exception: submit_errors_metric(context) raise finally: - self._after(event, context) + self._after(event, context, **kwargs) datadog_lambda_wrapper = _LambdaDecorator From 51d2b6dd753351cf50bd6a692c822e3c720d7eb3 Mon Sep 17 00:00:00 2001 From: Samuel Murillo Date: Tue, 3 Dec 2019 15:47:36 -0300 Subject: [PATCH 2/3] Modify shebang to bash This file has bash-specific syntax and having sh by default errors out --- scripts/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index c8643de7..5edccd90 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Unless explicitly stated otherwise all files in this repository are licensed # under the Apache License Version 2.0. From f876f1972c56faad1b9b5faa6902578e947f6aad Mon Sep 17 00:00:00 2001 From: Samuel Murillo Date: Wed, 4 Dec 2019 16:20:50 -0300 Subject: [PATCH 3/3] Remove unused kwargs --- datadog_lambda/wrapper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datadog_lambda/wrapper.py b/datadog_lambda/wrapper.py index 683b6e91..f4230372 100644 --- a/datadog_lambda/wrapper.py +++ b/datadog_lambda/wrapper.py @@ -57,7 +57,7 @@ def __init__(self, func): patch_all() logger.debug("datadog_lambda_wrapper initialized") - def _before(self, event, context, **kwargs): + def _before(self, event, context): set_cold_start() try: submit_invocations_metric(context) @@ -69,7 +69,7 @@ def _before(self, event, context, **kwargs): except Exception: traceback.print_exc() - def _after(self, event, context, **kwargs): + def _after(self, event, context): try: if not self.flush_to_log: lambda_stats.flush(float("inf")) @@ -77,14 +77,14 @@ def _after(self, event, context, **kwargs): traceback.print_exc() def __call__(self, event, context, **kwargs): - self._before(event, context, **kwargs) + self._before(event, context) try: return self.func(event, context, **kwargs) except Exception: submit_errors_metric(context) raise finally: - self._after(event, context, **kwargs) + self._after(event, context) datadog_lambda_wrapper = _LambdaDecorator