<@ULVA73B9P> can i add a tag to a flow run?
# ask-marvin
r
@Marvin can i add a tag to a flow run?
m
Yes, you can add a tag to a flow run in Prefect 3.x. You can use the
tags
context manager to apply tags to flow runs. Here is a basic example:
Copy code
python
from prefect import flow, tags

TAG_NAME = "example-tag"

@flow
def my_flow():
    # Your flow logic here
    pass

if __name__ == "__main__":
    with tags(TAG_NAME):
        my_flow()
In this example, the flow run for
my_flow
will be tagged with
"example-tag"
. This can be useful for organizing and managing flow runs, especially when dealing with concurrency limits or triggering downstream processes based on tags. For more detailed examples, you can refer to this GitHub example.
r
@Marvin no like i want to add it to the flow run during the run so i can filter based on events that occurred in the flow (e.g. failure during file transfer, failure during model run, etc.)
m
Currently, there isn't a direct way to dynamically add or modify tags on a flow run during its execution in Prefect 3.x. Tags are generally applied when flows are defined or deployed, and modifying them on-the-fly based on runtime conditions isn't supported natively. However, you can implement a workaround by logging specific events or states to Prefect's logging system and then using those logs to filter or trigger actions. For instance, you can log messages like "TAG: file_transfer_failure" when a specific event occurs, and then search logs for these indicators. If dynamic tagging is a critical feature for your workflow, consider submitting a feature request or checking existing issues on the Prefect GitHub repository to see if there are any ongoing discussions or workarounds shared by the community.