Skip to content

Commit 6308260

Browse files
committed
Add encode_authorizer_context.
1 parent adfe3ec commit 6308260

3 files changed

Lines changed: 3 additions & 7 deletions

File tree

datadog_lambda/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class Config:
8080

8181
make_inferred_span = _get_env("DD_TRACE_MANAGED_SERVICES", "true", as_bool,
8282
depends_on_tracing=True)
83+
encode_authorizer_context = _get_env("DD_ENCODE_AUTHORIZER_CONTEXT", "true", as_bool,
84+
depends_on_tracing=True)
8385

8486
local_test = _get_env("DD_LOCAL_TEST", "false", as_bool)
8587

datadog_lambda/wrapper.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
logger = logging.getLogger(__name__)
6060

6161
DD_TRACE_MANAGED_SERVICES = "DD_TRACE_MANAGED_SERVICES"
62-
DD_ENCODE_AUTHORIZER_CONTEXT = "DD_ENCODE_AUTHORIZER_CONTEXT"
6362
DD_DECODE_AUTHORIZER_CONTEXT = "DD_DECODE_AUTHORIZER_CONTEXT"
6463
DD_COLD_START_TRACING = "DD_COLD_START_TRACING"
6564
DD_REQUESTS_SERVICE_NAME = "DD_REQUESTS_SERVICE_NAME"
@@ -129,9 +128,6 @@ def __init__(self, func):
129128
depends_on_dd_tracing_enabled = (
130129
lambda original_boolean: config.trace_enabled and original_boolean
131130
)
132-
self.encode_authorizer_context = depends_on_dd_tracing_enabled(
133-
os.environ.get(DD_ENCODE_AUTHORIZER_CONTEXT, "true").lower() == "true"
134-
)
135131
self.decode_authorizer_context = depends_on_dd_tracing_enabled(
136132
os.environ.get(DD_DECODE_AUTHORIZER_CONTEXT, "true").lower() == "true"
137133
)
@@ -360,7 +356,7 @@ def _after(self, event, context):
360356
if exception_replay_env_var:
361357
LogsIntakeUploaderV1._instance.periodic()
362358

363-
if self.encode_authorizer_context and is_authorizer_response(self.response):
359+
if config.encode_authorizer_context and is_authorizer_response(self.response):
364360
self._inject_authorizer_span_headers(
365361
event.get("requestContext", {}).get("requestId")
366362
)

tests/test_wrapper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,8 @@ def lambda_handler(event, context):
622622
class TestLambdaDecoratorSettings(unittest.TestCase):
623623
@patch("datadog_lambda.config.Config.trace_enabled", False)
624624
def test_some_envs_should_depend_on_dd_tracing_enabled(self):
625-
os.environ[wrapper.DD_ENCODE_AUTHORIZER_CONTEXT] = "true"
626625
os.environ[wrapper.DD_DECODE_AUTHORIZER_CONTEXT] = "true"
627626
decorator = wrapper._LambdaDecorator(func=None)
628-
self.assertFalse(decorator.encode_authorizer_context)
629627
self.assertFalse(decorator.decode_authorizer_context)
630628

631629

0 commit comments

Comments
 (0)