Skip to content

Commit

Permalink
fix: add typecheck to lambda wrapper (#533)
Browse files Browse the repository at this point in the history
* check if event is a dict before getting

* early exit in is_legacy_lambda_step_function
  • Loading branch information
avedmala authored Nov 5, 2024
1 parent 3e92292 commit e58b065
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion datadog_lambda/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ def is_legacy_lambda_step_function(event):
"""
Check if the event is a step function that called a legacy lambda
"""
event = event.get("Payload", {})
if not isinstance(event, dict) or "Payload" not in event:
return False

event = event.get("Payload")
return "Execution" in event and "StateMachine" in event and "State" in event


Expand Down
3 changes: 3 additions & 0 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ def test_is_legacy_lambda_step_function(self):
}
self.assertFalse(is_legacy_lambda_step_function(sf_event))

other_event = ["foo", "bar"]
self.assertFalse(is_legacy_lambda_step_function(other_event))


class TestXRayContextConversion(unittest.TestCase):
def test_convert_xray_trace_id(self):
Expand Down

0 comments on commit e58b065

Please sign in to comment.