Skip to content

Commit 9a23c2a

Browse files
committed
Add decode_authorizer_context.
1 parent 6308260 commit 9a23c2a

3 files changed

Lines changed: 4 additions & 14 deletions

File tree

datadog_lambda/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Config:
8282
depends_on_tracing=True)
8383
encode_authorizer_context = _get_env("DD_ENCODE_AUTHORIZER_CONTEXT", "true", as_bool,
8484
depends_on_tracing=True)
85+
decode_authorizer_context = _get_env("DD_DECODE_AUTHORIZER_CONTEXT", "true", as_bool,
86+
depends_on_tracing=True)
8587

8688
local_test = _get_env("DD_LOCAL_TEST", "false", as_bool)
8789

datadog_lambda/wrapper.py

Lines changed: 2 additions & 6 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_DECODE_AUTHORIZER_CONTEXT = "DD_DECODE_AUTHORIZER_CONTEXT"
6362
DD_COLD_START_TRACING = "DD_COLD_START_TRACING"
6463
DD_REQUESTS_SERVICE_NAME = "DD_REQUESTS_SERVICE_NAME"
6564
DD_SERVICE = "DD_SERVICE"
@@ -128,9 +127,6 @@ def __init__(self, func):
128127
depends_on_dd_tracing_enabled = (
129128
lambda original_boolean: config.trace_enabled and original_boolean
130129
)
131-
self.decode_authorizer_context = depends_on_dd_tracing_enabled(
132-
os.environ.get(DD_DECODE_AUTHORIZER_CONTEXT, "true").lower() == "true"
133-
)
134130
self.cold_start_tracing = depends_on_dd_tracing_enabled(
135131
os.environ.get(DD_COLD_START_TRACING, "true").lower() == "true"
136132
)
@@ -246,7 +242,7 @@ def _before(self, event, context):
246242
event,
247243
context,
248244
extractor=self.trace_extractor,
249-
decode_authorizer_context=self.decode_authorizer_context,
245+
decode_authorizer_context=config.decode_authorizer_context,
250246
)
251247
self.event_source = event_source
252248
# Create a Datadog X-Ray subsegment with the trace context
@@ -264,7 +260,7 @@ def _before(self, event, context):
264260
set_dd_trace_py_root(trace_context_source, config.merge_xray_traces)
265261
if config.make_inferred_span:
266262
self.inferred_span = create_inferred_span(
267-
event, context, event_source, self.decode_authorizer_context
263+
event, context, event_source, config.decode_authorizer_context
268264
)
269265
if self.data_streams_enabled:
270266
set_dsm_context(event, event_source)

tests/test_wrapper.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,6 @@ def lambda_handler(event, context):
619619
del os.environ["DD_DATA_STREAMS_ENABLED"]
620620

621621

622-
class TestLambdaDecoratorSettings(unittest.TestCase):
623-
@patch("datadog_lambda.config.Config.trace_enabled", False)
624-
def test_some_envs_should_depend_on_dd_tracing_enabled(self):
625-
os.environ[wrapper.DD_DECODE_AUTHORIZER_CONTEXT] = "true"
626-
decorator = wrapper._LambdaDecorator(func=None)
627-
self.assertFalse(decorator.decode_authorizer_context)
628-
629-
630622
class TestLambdaWrapperWithTraceContext(unittest.TestCase):
631623
xray_root = "1-5e272390-8c398be037738dc042009320"
632624
xray_parent = "94ae789b969f1cc5"

0 commit comments

Comments
 (0)