10000 [BUGFIX] Fix how we look up the client context (#107) · DataDog/datadog-lambda-python@a90a045 · GitHub
[go: up one dir, main page]

Skip to content

Commit a90a045

Browse files
authored
[BUGFIX] Fix how we look up the client context (#107)
* fix how we look up the client context * fix lint
1 parent 9646080 commit a90a045

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

datadog_lambda/tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def extract_context_from_lambda_context(lambda_context):
9999
"""
100100
client_context = lambda_context.client_context
101101

102-
if client_context and "custom" in client_context:
103-
dd_data = client_context.get("custom", {}).get("_datadog", {})
102+
if client_context and client_context.custom:
103+
dd_data = client_context.custom.get("_datadog", {})
104104
trace_id = dd_data.get(TraceHeader.TRACE_ID)
105105
parent_id = dd_data.get(TraceHeader.PARENT_ID)
106106
sampling_priority = dd_data.get(TraceHeader.SAMPLING_PRIORITY)

tests/test_tracing.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test"
2323

2424

25+
class ClientContext(object):
26+
def __init__(self, custom=None):
27+
self.custom = custom
28+
29+
2530
def get_mock_context(
2631
aws_request_id="request-id-1",
2732
memory_limit_in_mb="256",
2833
invoked_function_arn=function_arn,
2934
function_version="1",
30-
client_context={},
35+
custom=None,
3136
):
3237
lambda_context = MagicMock()
3338
lambda_context.aws_request_id = aws_request_id
3439
lambda_context.memory_limit_in_mb = memory_limit_in_mb
3540
lambda_context.invoked_function_arn = invoked_function_arn
3641
lambda_context.function_version = function_version
37-
lambda_context.client_context = client_context
42+
lambda_context.client_context = ClientContext(custom)
3843
return lambda_context
3944

4045

@@ -205,13 +210,11 @@ def test_with_sqs_distributed_datadog_trace_data(self):
205210

206211
def test_with_client_context_datadog_trace_data(self):
207212
lambda_ctx = get_mock_context(
208-
client_context={
209-
"custom": {
210-
"_datadog": {
211-
TraceHeader.TRACE_ID: "666",
212-
TraceHeader.PARENT_ID: "777",
213-
TraceHeader.SAMPLING_PRIORITY: "1",
214-
}
213+
custom={
214+
"_datadog": {
215+
TraceHeader.TRACE_ID: "666",
216+
TraceHeader.PARENT_ID: "777",
217+
TraceHeader.SAMPLING_PRIORITY: "1",
215218
}
216219
}
217220
)

0 commit comments

Comments
 (0)
0