Skip to content

Commit 6b42cc4

Browse files
committed
Add decode_authorizer_context.
1 parent d0ef887 commit 6b42cc4

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
@@ -57,7 +57,6 @@
5757
logger = logging.getLogger(__name__)
5858

5959
DD_TRACE_MANAGED_SERVICES = "DD_TRACE_MANAGED_SERVICES"
60-
DD_DECODE_AUTHORIZER_CONTEXT = "DD_DECODE_AUTHORIZER_CONTEXT"
6160
DD_COLD_START_TRACING = "DD_COLD_START_TRACING"
6261
DD_REQUESTS_SERVICE_NAME = "DD_REQUESTS_SERVICE_NAME"
6362
DD_SERVICE = "DD_SERVICE"
@@ -125,9 +124,6 @@ def __init__(self, func):
125124
depends_on_dd_tracing_enabled = (
126125
lambda original_boolean: config.trace_enabled and original_boolean
127126
)
128-
self.decode_authorizer_context = depends_on_dd_tracing_enabled(
129-
os.environ.get(DD_DECODE_AUTHORIZER_CONTEXT, "true").lower() == "true"
130-
)
131127
self.cold_start_tracing = depends_on_dd_tracing_enabled(
132128
os.environ.get(DD_COLD_START_TRACING, "true").lower() == "true"
133129
)
@@ -229,7 +225,7 @@ def _before(self, event, context):
229225
event,
230226
context,
231227
extractor=self.trace_extractor,
232-
decode_authorizer_context=self.decode_authorizer_context,
228+
decode_authorizer_context=config.decode_authorizer_context,
233229
)
234230
self.event_source = event_source
235231
# Create a Datadog X-Ray subsegment with the trace context
@@ -247,7 +243,7 @@ def _before(self, event, context):
247243
set_dd_trace_py_root(trace_context_source, config.merge_xray_traces)
248244
if config.make_inferred_span:
249245
self.inferred_span = create_inferred_span(
250-
event, context, event_source, self.decode_authorizer_context
246+
event, context, event_source, config.decode_authorizer_context
251247
)
252248
self.span = create_function_execution_span(
253249
context=context,

tests/test_wrapper.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,6 @@ def return_type_test(event, context):
559559
self.assertFalse(MockPrintExc.called)
560560

561561

562-
class TestLambdaDecoratorSettings(unittest.TestCase):
563-
@patch("datadog_lambda.config.Config.trace_enabled", False)
564-
def test_some_envs_should_depend_on_dd_tracing_enabled(self):
565-
os.environ[wrapper.DD_DECODE_AUTHORIZER_CONTEXT] = "true"
566-
decorator = wrapper._LambdaDecorator(func=None)
567-
self.assertFalse(decorator.decode_authorizer_context)
568-
569-
570562
class TestLambdaWrapperWithTraceContext(unittest.TestCase):
571563
xray_root = "1-5e272390-8c398be037738dc042009320"
572564
xray_parent = "94ae789b969f1cc5"

0 commit comments

Comments
 (0)