airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Log exceptions as warnings till the final attempt

Open nitinmuteja opened this issue 3 years ago • 11 comments

Description

We have an integration with sentry on Google cloud composer. We would like to be alerted for any exceptions happening in airflow , but don't want to be alerted when those exceptions would be retried. We tried setting alert conditions on number of errors, but it does not solve the problem as we have hundreds of instances of a DAG running.

Requirements:

  1. Log as warning when try_number is less than equal to max_tries.
  2. Log as an error in the final try.

Use case/motivation

No response

Related issues

No response

Are you willing to submit a PR?

  • [X] Yes I am willing to submit a PR!

Code of Conduct

nitinmuteja avatar Jun 28 '23 18:06 nitinmuteja

Not sure how you would implement it, I see no obvious way that would be good but if you can propose a generic way of approaching it in PR, I am sure we can discuss it.

Assigned you.

potiuk avatar Jun 29 '23 13:06 potiuk

BTW. Likely you could do it by implementing a custom Task Log Handler without adding anything to Airflow. Just look what you can do it and if this is just customisation of it, then there is no need for genericness - you could implement your own task handler simply. https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/logging-tasks.html#implementing-a-custom-file-task-handler

potiuk avatar Jun 29 '23 13:06 potiuk

Ah no - scrap that. It's about sentry, so likely you are doing it by our sentry integration. Feel free to propose PR.

potiuk avatar Jun 29 '23 14:06 potiuk

@nitinmuteja @potiuk If no one has started work on this, i would be happy to work and propose a PR for this. (Need some hint on where to start though)

amoghrajesh avatar Jul 22 '23 11:07 amoghrajesh

I am not sure if it is even needed or how to approach it - but maybe @nitinmuteja might guide you.

potiuk avatar Jul 30 '23 15:07 potiuk

@amoghrajesh could not find time to submit this. You can handle the exceptions in taskinstance.py and then based on configuration we can decide whether to log it as an error or warning. Rule- If the task run number <=retry count then log it as a warning, if it is final attempt then log as an error.

nitinmuteja avatar Aug 02 '23 17:08 nitinmuteja

We are talking about airfllow/models/taskinstance.py right? @nitinmuteja

amoghrajesh avatar Aug 03 '23 03:08 amoghrajesh

Hi @amoghrajesh, I noticed this issue has been open for a while with no PR yet. Are you still planning to work on it? If not, I'd be happy to pick it up.

andreahlert avatar Feb 08 '26 07:02 andreahlert

@nitinmuteja We are unassigning you from this issue as part of our updated assignment policy.

This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.

We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.

potiuk avatar Mar 02 '26 19:03 potiuk

@potiuk I had created a task handler within a custom operator to handle sentry errors as we needed the changes in our solution immediately. @amoghrajesh seemed to have taken over earlier, but I agree anyone can takeover this.I will assign this to myself I plan to work on this soon.

nitinmuteja avatar Mar 02 '26 20:03 nitinmuteja

Hi, I'd like to work on this issue. My plan: in the task execution path, log retryable task failures at warning level while retries remain, and only log at error level on the final attempt. I'll open a PR shortly. Please let me know if this approach sounds right or if there's a preferred place for the change.

dasarijashwanth avatar Nov 27 '26 06:11 dasarijashwanth