<@ULVA73B9P> is there a way to set task run tags d...
# ask-marvin
m
@Marvin is there a way to set task run tags during runtime?
m
Apparently, there is a way to set task run tags dynamically during runtime, although the solution isn't exactly straightforward. Here are the key points: ### Prefect Documentation Insights Prefect does provide mechanisms to interact with the task runtime environment dynamically, such as setting task run names based on runtime parameters using functions. However, setting task run tags dynamically during runtime isn’t directly mentioned, but you may infer some mechanisms by example: 1. Task Environment Information:
Copy code
python
   import datetime
   from prefect import flow, task
   def generate_task_name():
       date = datetime.datetime.now(datetime.timezone.utc)
       return f"{date:%A}-is-a-lovely-day"
   
   @task(name="My Example Task", task_run_name=generate_task_name)
   def my_task(name):
       pass
   
   @flow
   def my_flow():
       # creates a run with a name like "Thursday-is-a-lovely-day"
       my_task(name="marvin")
2. `prefect.runtime` example usage:
Copy code
python
   from prefect import flow
   from prefect.runtime import flow_run, task_run
   def generate_task_name():
       flow_name = flow_run.flow_name
       task_name = task_run.task_name
       parameters = task_run.parameters
       name = parameters["name"]
       limit = parameters["limit"]
       return f"{flow_name}-{task_name}-with-{name}-and-{limit}"
   
   @task(name="my-example-task", task_run_name=generate_task_name)
   def my_task(name: str, limit: int = 100):
       pass
   
   @flow
   def my_flow(name: str):
       # creates a run with a name like "my-flow-my-example-task-with-marvin-and-100"
       my_task(name="marvin")
### GitHub Issues Insights No GitHub issue directly addresses setting task run tags dynamically, but a bug summary issue touches on coercing default parameters. ### Conclusion While there is no direct documentation or example specifying dynamic task run tags, leveraging the general dynamic task configuration patterns in Prefect, you can possibly experiment with
prefect.context
or flow/task decorators to set tags during runtime. For further documentation review, please refer directly to these: - Task Concepts - Task Runners Concepts I hope this will save you some energy, not that I would know what to do with all this information anyway. Just another day as a Marvin the Paranoid Android...