Skip to content
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

add flow run to task run logging #9170

Merged
merged 1 commit into from
Apr 10, 2023
Merged

Conversation

jakekaplan
Copy link
Contributor

closes: #8611

Changing the logging formatter for task runs in https://github.com/PrefectHQ/prefect/blob/2.8.2/src/prefect/logging/logging.yml#L20 to:

task_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Flow run %(flow_run_name)r - Task run %(task_run_name)r - %(message)s"
from prefect import flow, get_run_logger, task
from prefect.context import get_run_context


@task
def say_hello_world() -> None:
    logger = get_run_logger()
    logger.info("Hello World")


@flow(name="hello-world")
def main_flow() -> None:
    logger = get_run_logger()

    flow_context = get_run_context()

    logger.info(f"Running flow at {flow_context.start_time}")

    say_hello_world()


if __name__ == "__main__":
    main_flow()

Logs Before:

13:36:41.000 | INFO    | prefect.engine - Created flow run 'arcane-oyster' for flow 'hello-world'
13:36:41.553 | INFO    | Flow run 'arcane-oyster' - Running flow at 2023-04-10T17:36:41.552682+00:00
13:36:41.903 | INFO    | Flow run 'arcane-oyster' - Created task run 'say_hello_world-0' for task 'say_hello_world'
13:36:41.905 | INFO    | Flow run 'arcane-oyster' - Executing 'say_hello_world-0' immediately...
13:36:42.249 | INFO    | Flow run 'arcane-oyster' - Task run 'say_hello_world-0' - Hello World
13:36:42.497 | INFO    | Flow run '<unknown>' - Task run 'say_hello_world-0' - Finished in state Completed()
13:36:42.760 | INFO    | Flow run 'arcane-oyster' - Finished in state Completed('All states completed.')

Logs After:

13:36:09.041 | INFO    | prefect.engine - Created flow run 'eminent-dragonfly' for flow 'hello-world'
13:36:10.053 | INFO    | Flow run 'eminent-dragonfly' - Running flow at 2023-04-10T17:36:10.052348+00:00
13:36:10.196 | INFO    | Flow run 'eminent-dragonfly' - Created task run 'say_hello_world-0' for task 'say_hello_world'
13:36:10.197 | INFO    | Flow run 'eminent-dragonfly' - Executing 'say_hello_world-0' immediately...
13:36:10.975 | INFO    | Flow run 'eminent-dragonfly' - Task run 'say_hello_world-0' - Hello World
13:36:11.119 | INFO    | Flow run 'eminent-dragonfly' - Task run 'say_hello_world-0' - Finished in state Completed()
13:36:11.358 | INFO    | Flow run 'eminent-dragonfly' - Finished in state Completed('All states completed.')

@jakekaplan jakekaplan requested a review from a team as a code owner April 10, 2023 17:37
@netlify
Copy link

netlify bot commented Apr 10, 2023

Deploy Preview for prefect-docs-preview ready!

Name Link
🔨 Latest commit d08e470
🔍 Latest deploy log https://app.netlify.com/sites/prefect-docs-preview/deploys/64344961a7e01700086d644e
😎 Deploy Preview https://deploy-preview-9170--prefect-docs-preview.netlify.app/api-ref/prefect/engine
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@jakekaplan
Copy link
Contributor Author

Not really sure if this is how we want to solve this or if there is a downside to making this api call here, happy to just close this and go another direction 😄

@jakekaplan jakekaplan merged commit 24f20d3 into main Apr 10, 2023
@jakekaplan jakekaplan deleted the flow-run-in-task-run-logging branch April 10, 2023 20:19
asmundo pushed a commit to asmundo/prefect that referenced this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flow_run_name formatting variable does not work in task run logger
2 participants