Skip to content

[BUGFIX] Fix how we look up the client context #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datadog_lambda/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def extract_context_from_lambda_context(lambda_context):
"""
client_context = lambda_context.client_context

if client_context and "custom" in client_context:
dd_data = client_context.get("custom", {}).get("_datadog", {})
if client_context and client_context.custom:
dd_data = client_context.custom.get("_datadog", {})
trace_id = dd_data.get(TraceHeader.TRACE_ID)
parent_id = dd_data.get(TraceHeader.PARENT_ID)
sampling_priority = dd_data.get(TraceHeader.SAMPLING_PRIORITY)
Expand Down
21 changes: 12 additions & 9 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test"


class ClientContext(object):
def __init__(self, custom=None):
self.custom = custom


def get_mock_context(
aws_request_id="request-id-1",
memory_limit_in_mb="256",
invoked_function_arn=function_arn,
function_version="1",
client_context={},
custom=None,
):
lambda_context = MagicMock()
lambda_context.aws_request_id = aws_request_id
lambda_context.memory_limit_in_mb = memory_limit_in_mb
lambda_context.invoked_function_arn = invoked_function_arn
lambda_context.function_version = function_version
lambda_context.client_context = client_context
lambda_context.client_context = ClientContext(custom)
return lambda_context


Expand Down Expand Up @@ -205,13 +210,11 @@ def test_with_sqs_distributed_datadog_trace_data(self):

def test_with_client_context_datadog_trace_data(self):
lambda_ctx = get_mock_context(
client_context={
"custom": {
"_datadog": {
TraceHeader.TRACE_ID: "666",
TraceHeader.PARENT_ID: "777",
TraceHeader.SAMPLING_PRIORITY: "1",
}
custom={
"_datadog": {
TraceHeader.TRACE_ID: "666",
TraceHeader.PARENT_ID: "777",
TraceHeader.SAMPLING_PRIORITY: "1",
}
}
)
Expand Down