When calling `Client().create_flow_run()` what is ...
# prefect-community
k
When calling
Client().create_flow_run()
what is the best way to inject some custom context? Would it be something like this at a high level:
Copy code
client = Client()
  with context(run_id=some_run_id):
    client.create_flow_run()
As a follow up, the use case for the above question is that we want to inject a custom run_id into the env variable
PREFECT__LOGGING__LOG_ATTRIBUTES="['run_id']"
so that our logger can collect that attribute. Would this be the correct approach?
j
You'd want to do something like:
Copy code
client = Client()
client.create_flow_run(context={"run_id": some_run_id})
k
I would have to add that environment variable as well right?
j
If
PREFECT__LOGGING__LOG_ATTRIBUTES
is required for whatever functionality you want here, then yes, that would need to be set in the flow run environment as well. You'd do that when configuring your agent/flow environment statically once, not as part of the call to
create_flow_run
.
k
gotcha, appreciate the help!
👍 1