Skip to content

Rework remote task log handling for the structlog era. - #48491

Merged
ashb merged 1 commit into
apache:mainfrom
astronomer:overhaul-task-logging
Apr 2, 2025
Merged

Rework remote task log handling for the structlog era.#48491
ashb merged 1 commit into
apache:mainfrom
astronomer:overhaul-task-logging

Conversation

@ashb

@ashbashb commented Mar 28, 2025

Copy link
Copy Markdown
Member

Previously this feature was built on top of the stdlib logging.Handler
interface, and it worked but had a few issues (even before we switched to
structlog for Task SDK):

  • we had to use what is in many ways a hack with the "set_context" to get
    information down in to the task handler.
  • Discovering of the configured task handler was somewhat baroque
  • The whole thing is just complex due to the features of stdlib logging
    (loggers, propagate, handler levels etc etc.)
  • The upload was triggered somewhat "automatically" inside close, which from
    an abstraction point of view is messy.

This changes things to have a more explicit interface purpose made for
uploading task log files and for reading them, and perhaps more crucially for
things like CloudWatch Logs, it (re)adds the ability to install a structlog
processor that will recieve every log message as it happens.

The return types for the read et al functions were confusing the living
daylights out of me, so I've created type alias to give the return types
explicit names to reduce (my) confusion.

@boring-cyborgboring-cyborgBot added area:logging area:providers area:task-sdk provider:amazon AWS/Amazon - related issues provider:google Google (including GCP) related issues provider:microsoft-azure Azure-related issues labels Mar 28, 2025
@ashbashb changed the title Rework remote task log handleing for the structlog era.🚧 Rework remote task log handleing for the structlog era.Mar 28, 2025
@ashbashb changed the title 🚧 Rework remote task log handleing for the structlog era.🚧 Rework remote task log handling for the structlog era.Mar 28, 2025
@ashb

This comment was marked as outdated.

@ashb
ashbforce-pushed the overhaul-task-logging branch 2 times, most recently from e25bd96 to e43c7bbCompareMarch 31, 2025 15:48
@ashbashb changed the title 🚧 Rework remote task log handling for the structlog era.Rework remote task log handling for the structlog era.Mar 31, 2025
@ashb
ashb marked this pull request as ready for review March 31, 2025 15:49
Comment threadairflow-core/src/airflow/logging/remote.py Outdated
Comment threadairflow-core/src/airflow/logging_config.py Outdated
Comment threadairflow-core/src/airflow/logging_config.py Outdated
Comment threadairflow-core/src/airflow/logging_config.py Outdated
Comment threadairflow-core/src/airflow/logging_config.py Outdated
Comment threadairflow-core/src/airflow/logging_config.py Outdated

@amoghrajeshamoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1
Some nits

Comment threadairflow-core/src/airflow/logging_config.py Outdated
Comment threadairflow-core/src/airflow/utils/log/file_task_handler.py Outdated
Comment threadairflow-core/src/airflow/utils/log/file_task_handler.py
Comment threadtask-sdk/src/airflow/sdk/log.py
Comment threadtask-sdk/src/airflow/sdk/log.py Outdated
@eladkal

Copy link
Copy Markdown
Contributor

Does this affect elasticsearch / opensearch logging? asking because I don't see changes in this PR for these providers

@ashb

ashb commented Apr 1, 2025

Copy link
Copy Markdown
MemberAuthor

Does this affect elasticsearch / opensearch logging? asking because I don't see changes in this PR for these providers

Oh yes, I forgot to deal with this. My plan for now is to make it fall back to the existing airflow.task handler.

(I also really don't like we have two almost identical providers for ES and OS. Thanks a lot Elastic.

@ashb
ashbforce-pushed the overhaul-task-logging branch from b6cea26 to 1d0c3ebCompareApril 1, 2025 09:26
Previously this feature was built on top of the stdlib logging.Handler
interface, and it worked but had a few issues (even before we switched to
structlog for Task SDK):
- we had to use what is in many ways a hack with the "set_context" to get
information down in to the task handler.
- Discovering of the configured task handler was somewhat baroque
- The whole thing is just complex due to the features of stdlib logging
(loggers, propagate, handler levels etc etc.)
- The upload was triggered somewhat "automatically" inside close, which from
an abstraction point of view is messy.
This changes things to have a more explicit interface purpose made for
uploading task log files and for reading them, and perhaps more crucially for
things like CloudWatch Logs, it (re)adds the ability to install a structlog
processor that will receive every log message as it happens.
The return types for the read et al functions were confusing the living
daylights out of me, so I've created type alias to give the return types
explicit names to reduce (my) confusion.
@ashb
ashbforce-pushed the overhaul-task-logging branch from 062fb4b to 6191c13CompareApril 2, 2025 12:44
@eladkal

Copy link
Copy Markdown
Contributor

We are missing handling for HdfsTaskHandler but I believe this is a niche one and we can do it later. created #48685 to followup

@ashb

ashb commented Apr 2, 2025

Copy link
Copy Markdown
MemberAuthor

mypy providers failure is fixed in #48686

@ashb

ashb commented Apr 2, 2025

Copy link
Copy Markdown
MemberAuthor

I haven't changed deps, everything but lowest provider deps is passing, so I'm merging this now.

@ashb
ashb merged commit c1088b6 into apache:mainApr 2, 2025
@ashb
ashb deleted the overhaul-task-logging branch April 2, 2025 14:10
@ashbashb linked an issue Apr 2, 2025 that may be closed by this pull request
2 tasks
@jason810496

Copy link
Copy Markdown
Member

We are missing handling for HdfsTaskHandler but I believe this is a niche one and we can do it later. created #48685 to followup

I think ElasticsearchTaskHandler and RedisTaskHandler are missing in this PR. I will create separate issues to track them.

@ashb

ashb commented Apr 3, 2025

Copy link
Copy Markdown
MemberAuthor

@jason810496 ES and OS are a bit of a mess tbh. They are entirely too specialized, and 95% of that isn't needed anymore now that Task SDK writes out JSON logs natively.

@eladkal

Copy link
Copy Markdown
Contributor

We can decide that these two providers (Elastic, open search) would be Airflow 3+ compatible from next release.
they get code changes very rarely anyway. If it simplify stuff we can do that.

aaron-y-chen pushed a commit to aaron-y-chen/airflow that referenced this pull request Apr 4, 2025
Previously this feature was built on top of the stdlib logging.Handler
interface, and it worked but had a few issues (even before we switched to
structlog for Task SDK):
- we had to use what is in many ways a hack with the "set_context" to get
information down in to the task handler.
- Discovering of the configured task handler was somewhat baroque
- The whole thing is just complex due to the features of stdlib logging
(loggers, propagate, handler levels etc etc.)
- The upload was triggered somewhat "automatically" inside close, which from
an abstraction point of view is messy.
This changes things to have a more explicit interface purpose made for
uploading task log files and for reading them, and perhaps more crucially for
things like CloudWatch Logs, it (re)adds the ability to install a structlog
processor that will receive every log message as it happens.
The return types for the read et al functions were confusing the living
daylights out of me, so I've created type alias to give the return types
explicit names to reduce (my) confusion.
diogotrodrigues pushed a commit to diogotrodrigues/airflow that referenced this pull request Apr 6, 2025
Previously this feature was built on top of the stdlib logging.Handler
interface, and it worked but had a few issues (even before we switched to
structlog for Task SDK):
- we had to use what is in many ways a hack with the "set_context" to get
information down in to the task handler.
- Discovering of the configured task handler was somewhat baroque
- The whole thing is just complex due to the features of stdlib logging
(loggers, propagate, handler levels etc etc.)
- The upload was triggered somewhat "automatically" inside close, which from
an abstraction point of view is messy.
This changes things to have a more explicit interface purpose made for
uploading task log files and for reading them, and perhaps more crucially for
things like CloudWatch Logs, it (re)adds the ability to install a structlog
processor that will receive every log message as it happens.
The return types for the read et al functions were confusing the living
daylights out of me, so I've created type alias to give the return types
explicit names to reduce (my) confusion.
simonprydden pushed a commit to simonprydden/airflow that referenced this pull request Apr 8, 2025
Previously this feature was built on top of the stdlib logging.Handler
interface, and it worked but had a few issues (even before we switched to
structlog for Task SDK):
- we had to use what is in many ways a hack with the "set_context" to get
information down in to the task handler.
- Discovering of the configured task handler was somewhat baroque
- The whole thing is just complex due to the features of stdlib logging
(loggers, propagate, handler levels etc etc.)
- The upload was triggered somewhat "automatically" inside close, which from
an abstraction point of view is messy.
This changes things to have a more explicit interface purpose made for
uploading task log files and for reading them, and perhaps more crucially for
things like CloudWatch Logs, it (re)adds the ability to install a structlog
processor that will receive every log message as it happens.
The return types for the read et al functions were confusing the living
daylights out of me, so I've created type alias to give the return types
explicit names to reduce (my) confusion.
YoannAbriel added a commit to YoannAbriel/airflow that referenced this pull request Mar 5, 2026
…g config
When remote_task_handler_kwargs contains FileTaskHandler parameters like
max_bytes, backup_count, or delay, these were incorrectly passed to
RemoteLogIO constructors (e.g., WasbRemoteLogIO, S3RemoteLogIO) which
don't accept them, causing TypeError on startup.
This was a regression introduced when RemoteLogIO classes were split out
from the handlers in PR apache#48491. The remote_task_handler_kwargs dict was
passed entirely to RemoteLogIO and then cleared, so handler-level params
were never applied to the FileTaskHandler.
The fix separates the kwargs: handler-specific parameters (max_bytes,
backup_count, delay) are preserved and applied to the handler config,
while the remaining kwargs are passed to the RemoteLogIO constructor.
Closes: apache#58770
YoannAbriel added a commit to YoannAbriel/airflow that referenced this pull request Mar 5, 2026
…g config
When remote_task_handler_kwargs contains FileTaskHandler parameters like
max_bytes, backup_count, or delay, these were incorrectly passed to
RemoteLogIO constructors (e.g., WasbRemoteLogIO, S3RemoteLogIO) which
don't accept them, causing TypeError on startup.
This was a regression introduced when RemoteLogIO classes were split out
from the handlers in PR apache#48491. The remote_task_handler_kwargs dict was
passed entirely to RemoteLogIO and then cleared, so handler-level params
were never applied to the FileTaskHandler.
The fix separates the kwargs: handler-specific parameters (max_bytes,
backup_count, delay) are preserved and applied to the handler config,
while the remaining kwargs are passed to the RemoteLogIO constructor.
Closes: apache#58770
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:loggingarea:providersarea:task-sdkprovider:amazonAWS/Amazon - related issuesprovider:googleGoogle (including GCP) related issuesprovider:microsoft-azureAzure-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task SDK cannot upload remote logs due to missing handlers

8 participants

@ashb@eladkal@jason810496@kaxil@Adaverse@amoghrajesh@o-nikolas@jedcunningham