Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
332 stars 103 forks source link

Add hook for exception handling #1531

Open tanyunshi opened 1 month ago

tanyunshi commented 1 month ago

Binding Type

No response

Expected Behavior

I am looking for a place to centralize the exception handling. For example, to log all exceptions with the invocation id and a correlation ID.

As I cannot use a base class in azure functions (as they are functions :) ), I suppose that I can use the extensions, where I can implement behaviors for an event.

I wished I could use post_invocation_app_level but then I realize that this method will not be called if the function fails

It would be useful to have a method like "exception_invocation_app_level" for the application level extensions. The method is called once an exception is raised in the function execution. The function context, invocation args and the raised exception are passed to the methode.

Relevant sample code snipped

No response

Additional Information

No response

bhagyshricompany commented 1 month ago

thanks for reporting will discuss and update you.Thanks

rokcarl commented 1 month ago

I have a similar requirement. In my case, I will be implementing Sentry, so I want a way to be able to handle all the exceptions. All my attempts have failed. Is there an existing way of hooking into this? I've also used Sentry's serverless decorator, but even though it's wrapping a function that gets called, the wrapped function just doesn't throw an error as it's apparently caught by Azure.

bhagyshricompany commented 3 weeks ago

@gavin-aguiar please confirm.Thanks

gavin-aguiar commented 3 weeks ago

Hi all, we are working on a feature to provide this functionality. We don't have an ETA as of now but will keep this issue updated once the feature is released.

tanyunshi commented 3 weeks ago

Hi all, we are working on a feature to provide this functionality. We don't have an ETA as of now but will keep this issue updated once the feature is released.

Really appreciate it ! Pls keep us informed. :)