AIP-72: Add logging for exception in Task Runner#45502
Merged
kaxil merged 1 commit intoapache:mainfrom Jan 9, 2025
Merged
Conversation
Currently, when a task fails there are no log which makes it very difficult to debug.
Before:
```
{"file":"/files/dags/get_context.py","timestamp":"2025-01-09T07:17:10.066994","logger":"task","event":"DAG file parsed","level":"debug"}
{"json":"{\"rendered_fields\":{\"templates_dict\":null,\"op_args\":\"()\",\"op_kwargs\":{}},\"type\":\"SetRenderedFields\"}\n","timestamp":"2025-01-09T07:17:10.067242","logger":"task","event":"Sending request","level":"debug"}
{"json":"{\"state\":\"failed\",\"end_date\":\"2025-01-09T07:17:10.071585Z\",\"type\":\"TaskState\"}\n","timestamp":"2025-01-09T07:17:10.071638","logger":"task","event":"Sending request","level":"debug"}
```
After:
```
{"file":"/files/dags/get_context.py","timestamp":"2025-01-09T07:17:10.066994","logger":"task","event":"DAG file parsed","level":"debug"}
{"json":"{\"rendered_fields\":{\"templates_dict\":null,\"op_args\":\"()\",\"op_kwargs\":{}},\"type\":\"SetRenderedFields\"}\n","timestamp":"2025-01-09T07:17:10.067242","logger":"task","event":"Sending request","level":"debug"}
{"timestamp":"2025-01-09T07:17:10.071412","logger":"task","error_detail":[{"exc_type":"AirflowException","exc_value":"Current context was requested but no context was found! Are you running within an airflow task?","syntax_error":null,"is_cause":false,"frames":[{"filename":"/opt/airflow/task_sdk/src/airflow/sdk/execution_time/task_runner.py","lineno":457,"name":"run"},{"filename":"/opt/airflow/airflow/models/baseoperator.py","lineno":376,"name":"wrapper"},{"filename":"/opt/airflow/airflow/decorators/base.py","lineno":261,"name":"execute"},{"filename":"/opt/airflow/airflow/models/baseoperator.py","lineno":376,"name":"wrapper"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":196,"name":"execute"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":222,"name":"execute_callable"},{"filename":"/opt/airflow/airflow/utils/operator_helpers.py","lineno":269,"name":"run"},{"filename":"/files/dags/get_context.py","lineno":16,"name":"template_test"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":1153,"name":"get_current_context"}]}],"event":"Task failed with exception","level":"error"}
{"json":"{\"state\":\"failed\",\"end_date\":\"2025-01-09T07:17:10.071585Z\",\"type\":\"TaskState\"}\n","timestamp":"2025-01-09T07:17:10.071638","logger":"task","event":"Sending request","level":"debug"}
```
phanikumv
approved these changes
Jan 9, 2025
karenbraganz
pushed a commit
to karenbraganz/airflow
that referenced
this pull request
Jan 13, 2025
HariGS-DB
pushed a commit
to HariGS-DB/airflow
that referenced
this pull request
Jan 16, 2025
got686-yandex
pushed a commit
to got686-yandex/airflow
that referenced
this pull request
Jan 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, when a task fails there are no log which makes it very difficult to debug.
Before:
{"file":"/files/dags/get_context.py","timestamp":"2025-01-09T07:17:10.066994","logger":"task","event":"DAG file parsed","level":"debug"} {"json":"{\"rendered_fields\":{\"templates_dict\":null,\"op_args\":\"()\",\"op_kwargs\":{}},\"type\":\"SetRenderedFields\"}\n","timestamp":"2025-01-09T07:17:10.067242","logger":"task","event":"Sending request","level":"debug"} {"json":"{\"state\":\"failed\",\"end_date\":\"2025-01-09T07:17:10.071585Z\",\"type\":\"TaskState\"}\n","timestamp":"2025-01-09T07:17:10.071638","logger":"task","event":"Sending request","level":"debug"}After:
{"file":"/files/dags/get_context.py","timestamp":"2025-01-09T07:17:10.066994","logger":"task","event":"DAG file parsed","level":"debug"} {"json":"{\"rendered_fields\":{\"templates_dict\":null,\"op_args\":\"()\",\"op_kwargs\":{}},\"type\":\"SetRenderedFields\"}\n","timestamp":"2025-01-09T07:17:10.067242","logger":"task","event":"Sending request","level":"debug"} {"timestamp":"2025-01-09T07:17:10.071412","logger":"task","error_detail":[{"exc_type":"AirflowException","exc_value":"Current context was requested but no context was found! Are you running within an airflow task?","syntax_error":null,"is_cause":false,"frames":[{"filename":"/opt/airflow/task_sdk/src/airflow/sdk/execution_time/task_runner.py","lineno":457,"name":"run"},{"filename":"/opt/airflow/airflow/models/baseoperator.py","lineno":376,"name":"wrapper"},{"filename":"/opt/airflow/airflow/decorators/base.py","lineno":261,"name":"execute"},{"filename":"/opt/airflow/airflow/models/baseoperator.py","lineno":376,"name":"wrapper"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":196,"name":"execute"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":222,"name":"execute_callable"},{"filename":"/opt/airflow/airflow/utils/operator_helpers.py","lineno":269,"name":"run"},{"filename":"/files/dags/get_context.py","lineno":16,"name":"template_test"},{"filename":"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py","lineno":1153,"name":"get_current_context"}]}],"event":"Task failed with exception","level":"error"} {"json":"{\"state\":\"failed\",\"end_date\":\"2025-01-09T07:17:10.071585Z\",\"type\":\"TaskState\"}\n","timestamp":"2025-01-09T07:17:10.071638","logger":"task","event":"Sending request","level":"debug"}^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.