<@ULVA73B9P> In Prefect 3, if I have a task launch...
# ask-marvin
n
@Marvin In Prefect 3, if I have a task launching a deployment as a subflow, is there a way for that task to inherit and show automatically ALL logs of that subflow?
m
thought for 146.9 seconds
Short answer: no — not automatically. In Prefect 3, if a task launches a deployment as a subflow, the child flow run keeps its own log stream. Those logs do not automatically appear inside the parent task’s logs. What does happen: - the child deployment run is linked to the parent via
parent_task_run_id
- the child has its own
flow_run_id
- logs are stored against that child
flow_run_id
, not “bubbled up” into the parent task log output So if you want the parent task to “show” all subflow logs, you have to do that manually. Typical options: 1. Log a summary in the parent task - deployment run ID - final state - link to the child run in the UI 2. Query the child run’s logs via the API/client and re-emit them from the parent task - workable, but manual - can get noisy / duplicate logs 3. Use the UI to inspect the child run separately - this is usually the intended Prefect model Example pattern:
Copy code
python
from prefect import task
from prefect.deployments import run_deployment
from prefect.logging import get_run_logger

@task
async def launch_subflow():
    logger = get_run_logger()

    flow_run = await run_deployment(
        name="my-flow/my-deployment"
    )

    <http://logger.info|logger.info>(f"Subflow run created: {flow_run.id}")
    <http://logger.info|logger.info>(f"Subflow final state: {flow_run.state_name}")
If you really want to fetch child logs and re-log them, you’d need to: - find the child flow run(s) - read their logs through the Prefect client - emit those log lines again from the parent context Important caveat: - this replays logs into the parent; it is not true inheritance - timestamps/order may not perfectly match live execution - you may end up with duplicated logs in your system If you want, I can give you a complete Prefect 3 example that: - launches a deployment as a subflow - waits for completion - fetches all child logs - re-emits them in the parent task log stream Relevant docs: - Run deployments - Flows - Logging