One function

extract_http_status_code_tag in DataDog/datadog-lambda-python

The author described this change as Fix get status_code (#117). It counts as a record because the check below fails on the code as it stood at c70d9eda0 and passes on e44bc02c3, with nothing else changed between the two runs.

Fix saved2021-03-10
Sharing licenceApache-2.0 · LICENSE
Change size+3 1

What the code was meant to do, written into the code itself as a docstring

If the Lambda was triggered by API Gateway or ALB add the returned status code as a tag to the function execution span.

The change

1515 if response is None:
1616 # Return a 502 status if no response is found
1717 status_code = "502"
18- elif response.get("statusCode"):
18+ elif hasattr(response, "get"):
1919 status_code = response.get("statusCode")
20+ elif hasattr(response, "status_code"):
21+ status_code = response.status_code
2022
2123 return status_code

The check that tells the two apart

failpass·tests/test_trigger.py::ExtractHTTPStatusCodeTag::test_extract_http_status_code_tag_from_response_object

Check file tests/test_trigger.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itc70d9eda06af37321c4012a8a6048432d332b808
Broken version dated2021-02-23
Moduledatadog_lambda.trigger
Units changedextract_http_status_code_tag
Fingerprint52da75d96c973806
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.