-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix remote logging CloudWatch handler initialization and stream name assignment #51022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix remote logging CloudWatch handler initialization and stream name assignment #51022
Conversation
|
add back handler caching, as initializing the handler is a heavy operation, it sets up all queues in Watchtower and establishes sessions. It's inefficient to perform this on every access, especially via a property. Instead of closing the handler, we can use flush, which sends all queued logs without shutting down the handler. |
|
BTW Will check this in a separate PR. |
providers/amazon/src/airflow/providers/amazon/aws/log/cloudwatch_task_handler.py
Show resolved
Hide resolved
…assignment (apache#51022) * Fix remote logging CloudWatch handler initialization and stream name assignment * Flush the logs when upload function calls
…assignment (apache#51022) * Fix remote logging CloudWatch handler initialization and stream name assignment * Flush the logs when upload function calls

closes: #50802
Currently, logging to CloudWatch only occurs at startup—specifically, when the executor first launches and triggers a DAG. Logging functions correctly for this initial run, but fails on subsequent runs. This issue arises because the handler is implemented as a cached_property, and we call self.handler.close() during the final log upload. In the close() method, the shutdown parameter is set to True https://github.com/kislyuk/watchtower/blob/main/watchtower/__init__.py#L463, which blocks further logging and prevents logs from being uploaded to CloudWatch.
Additionally, we should ensure that the stream name is explicitly assigned if it's available in the logger. Otherwise, we risk reusing a previously configured stream name, which can result in logs being written to the incorrect stream.
Before:
After:

^ 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 airflow-core/newsfragments.