Skip to content

Fix error when APIGateway headers are None #259

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
Nov 2, 2022
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
2 changes: 1 addition & 1 deletion datadog_lambda/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def extract_context_from_http_event_or_context(event, lambda_context):

Falls back to lambda context if no trace data is found in the `headers`
"""
headers = event.get("headers", {})
headers = event.get("headers", {}) or {}
lowercase_headers = {k.lower(): v for k, v in headers.items()}

trace_id = lowercase_headers.get(TraceHeader.TRACE_ID)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,3 +1237,11 @@ def test_mark_trace_as_error_for_5xx_responses_sends_error_metric_and_set_error_
)
mock_submit_errors_metric.assert_called_once()
self.assertEqual(1, mock_span.error)

def test_no_error_with_nonetype_headers(self):
lambda_ctx = get_mock_context()
ctx, source = extract_dd_trace_context(
{"headers": None},
lambda_ctx,
)
self.assertEqual(ctx, None)