Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions datadog_lambda/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ def is_legacy_lambda_step_function(event):
"""
Check if the event is a step function that called a legacy lambda
"""
if not isinstance(event, dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have other code that assumes that this is a dict in the wrapper flow that will trip over this problem?

also, should we look at the contents of the list if it is a list? or is that impossible for a legacy lambda step function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont' think we need to look through the whole list. If it's not a dict, we know right away that it's not a step function event.

As for the isinstance, we do have other checks for if the event is a dict. For example in determining trace propagation we skip altogether if it's not a dict. Best answer could even be surrounding the whole thing with a try/except.

Copy link
Contributor Author

@avedmala avedmala Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract_trigger_tags() which is called right after is_legacy_lambda_step_function() expects a dict, assuming there's more

it should be impossible for legacy lambda case

according to the issue

In this case the incoming event is not a dictionary but a list of dictionaries that's generated by a dynamodb stream in an aws eventbridge pipe with batching enabling

The customers use case might still break even with this quick fix

return False

event = event.get("Payload", {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't super related to this incident, but I think it's worth changing anyway. I'm wondering if we can exit early if "Payload" is not in the event. By then we already know that it's not gonna be a step function event. So, exiting early would prevent the allocation of the {} and all the searching on the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout 👍🏽 , will add an early exit

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
Loading