Ensure logging is configured on remote task workers#21379
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Ensure logging is configured on remote task workers#21379devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
When tasks execute on remote Dask/Ray workers via a serialized context, the worker process may never have called setup_logging(), so the APILogHandler is missing from Prefect loggers and task logs are silently lost. Add ensure_logging_setup() API in logging/configuration.py that encapsulates the PROCESS_LOGGING_CONFIG check and only calls setup_logging() if needed. Call it from both SyncTaskRunEngine and AsyncTaskRunEngine initialize_run() when a serialized context is present. Flush APILogHandler in the finally block to ensure logs are sent before the task result is returned. Closes #18082 Co-authored-by: Alex Streed <desertaxle@users.noreply.github.com> Co-Authored-By: alex.s <ajstreed1@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
When tasks run on remote Dask or Ray workers via a serialized context, the worker process may never have called
setup_logging(). This means theAPILogHandleris not attached to Prefect loggers and task run logs are silently lost.Closes #18082
Changes
New API in
prefect.logging.configuration:ensure_logging_setup()— idempotent function that callssetup_logging()only ifPROCESS_LOGGING_CONFIGhas not been populated. This keeps the internal state check encapsulated rather than leaking it to callers.is_logging_configured()— simple query for whether logging has been set up in this process.Task engine (
SyncTaskRunEngine/AsyncTaskRunEngine):initialize_run(), after enteringhydrated_context, callensure_logging_setup()whenself.context is not None(i.e., remote execution only — local task runs are unaffected).finallyblock, flushAPILogHandler(sync) /await APILogHandler.aflush()(async) to ensure queued logs are sent before the task result is returned to the orchestrator.Important review notes
"prefect.task_runs"logger and flushes matchingAPILogHandlerinstances, while async callsAPILogHandler.aflush()(a classmethod that callsAPILogWorker.drain_all()). The async path flushes all enqueued logs globally, not just for the current task run — worth verifying this is acceptable.is_logging_configured()is added and tested but not called by the implementation itself (ensure_logging_setup()checksPROCESS_LOGGING_CONFIGdirectly). It's exposed as public API for external consumers.dictConfigMockfixture pattern.Checklist
<link to issue>"mint.json.Link to Devin session: https://app.devin.ai/sessions/c7590302b0bc40df9fba83c32ba15f91
Requested by: @desertaxle