1fanwang opened a new pull request, #66395:
URL: https://github.com/apache/airflow/pull/66395

   ## Description
   
   When a listener hookimpl raises, the suppressed-exception log line now
   identifies which hook raised. The previous generic
   ``log.exception(\"error calling listener\")`` made it impossible to tell 
which
   of the registered hooks failed without re-reading the stack trace —
   especially painful when several listeners are registered and one of them
   sporadically misbehaves.
   
   New format:
   
   \`\`\`text
   error calling listener for hook 'on_task_instance_failed'
   \`\`\`
   
   The existing substring ``error calling listener`` remains in the message,
   so any downstream log-grep tooling continues to match.
   
   ## Scope
   
   This PR covers the **task instance** listener call sites only, mirroring
   the surface of #66394:
   
   - ``task-sdk/src/airflow/sdk/execution_time/task_runner.py`` — 5 sites
     (running, success, skipped, up_for_retry, failed)
   - ``airflow-core/src/airflow/models/taskinstance.py`` — 1 site (API
     server retry path)
   - 
``airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py``
     — split the single try/except wrapping three branches into per-branch
     try/except so each log line names exactly one hook
   
   DagRun, asset, dag-processing, and lifecycle listener call sites follow the
   same pattern and can be migrated as a follow-up; keeping this PR narrow
   makes the diff trivially reviewable.
   
   ## Behavior
   
   Listener-exception suppression is preserved — task execution is not
   affected by listener failures.
   
   ## Testing
   
   - Existing test ``test_listener_suppresses_exceptions`` (airflow-core) is
     extended to also assert the hook name appears in the captured log
     output. It uses the existing ``throwing_listener`` fixture which raises
     in ``on_task_instance_success``.
   - New unit test ``test_listener_error_log_includes_hook_name`` (task-sdk)
     registers a listener that raises in ``on_task_instance_success``,
     drives the runner, and asserts ``log.exception`` was called with
     ``(\"error calling listener for hook %r\", \"on_task_instance_success\")``.
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to