<@ULVA73B9P> Is there a utility available within t...
# marvin-in-the-wild
j
@Marvin Is there a utility available within the context of a flow run to get the full url to the prefect UI for that run? e.g https:_//app.prefect.cloud/account/{account_id}/workspace/{workspace_id}/runs/flow-run/{run_id}_
m
It appears that there isn't a specific documented utility to directly get the full URL for a flow run in the Prefect UI. However, you can construct the URL using Prefect runtime variables. Here's a basic approach to construct the URL manually:
Copy code
python
from prefect import flow
from prefect.runtime import flow_run

@flow
def generate_flow_run_url():
    flow_run_id = flow_run.id
    account_id = "your_account_id"  # Replace with your actual account ID
    workspace_id = "your_workspace_id"  # Replace with your actual workspace ID
    base_url = "<https://app.prefect.cloud>"
    url = f"{base_url}/account/{account_id}/workspace/{workspace_id}/flow-runs/flow-run/{flow_run_id}"
    return url

if __name__ == "__main__":
    print(generate_flow_run_url())
This script constructs the URL using the runtime variables and your specific account and workspace IDs. Adjust the
account_id
and
workspace_id
accordingly. For more detailed information, you can refer to the links provided in the search results: - Prefect Flows Documentation - Prefect Automations Documentation If you have any further questions or need additional assistance, please let me know.
j
@Marvin Just looking at the runtime source, doesn't get_flow_run_ui_url do this?
m
Yes, you're correct!
prefect.runtime.flow_run.get_flow_run_ui_url
indeed does provide the URL for viewing the flow run in the Prefect UI. Here's a simple example to use it within your flow:
Copy code
python
from prefect import flow
from prefect.runtime.flow_run import get_flow_run_ui_url

@flow
def display_flow_run_url():
    flow_run_url = get_flow_run_ui_url()
    print(f"Flow run URL: {flow_run_url}")

if __name__ == "__main__":
    display_flow_run_url()
This will fetch and print the URL to the Prefect UI for the current flow run. For more detailed information, you can refer to the links provided in the search results: - Runtime Context Guide - Automations Documentation If you have any more questions or need further assistance, feel free to ask!