Netflix-Skunkworks / raven-python-lambda

Sentry/Raven SDK Integration For AWS Lambda (python) and Serverless
Apache License 2.0
47 stars 15 forks source link

Error when using it with step-functions parallel state #34

Open vayias opened 6 years ago

vayias commented 6 years ago

Context: Step functions is a technology aws offers to coordinate and manage the execution of your lambdas.

Issue: Lambda function can have as input parameters, an event and a context. event is always guaranteed to be a dict.

In step-functions you can have multiple lambda functions get executed in parallel. The generated output of this parallel state, is an array with one element for each branch containing the output from that branch. That means that a lambda function that will get called after this parallel state, will have the parameter event being of type list instead of a dict.

So when you try to report to sentry using raven-python-lambda in this lambda function that event is not a dict, and so it breaks. It breaks because of the numerous event.get calls in the __init__.py file. Error is AttributeError: 'list' object has no attribute 'get'

I was thinking of creating a PR that simply will check if the type of event is a dict before doing attempting the event.get.

Do you guys think this is acceptable? Any thoughts around that? Will be happy to chat about this more.

kevgliss commented 6 years ago

A PR with that check seems reasonable, haven't played much with step functions myself.

vayias commented 6 years ago

Thanks for the response @kevgliss. Before creating the PR, I'm trying to figure out if anything will end-up braking in the underlying raven code as a result of this change. Any thoughts around that?

kevgliss commented 6 years ago

Thats an interesting question, I'm not sure how you would reconcile multiple events in the context of one lambda? i.e. when you are writing your lambda code is it expected that one lambda will process all of the events? Moreover, if any error is encountered should you report for only the event that caused the failure (probably) or report them all?

What you could do is write your lambda as if it expects one event (like a normal non step function), and let the decorator iterate over your events (if they exist) adding the most specific context (event) as it goes.

The only down side to that is the decorator is now part of the processing logic (converting list of dicts to list) which may not be what you want.