Michał Augoff
09/20/2023, 10:15 AMRyan Peden
09/20/2023, 6:07 PMrun
is called on your block, ""PREFECT__FLOW_RUN_ID"
should be available in the block's env
dict.
You could probably use that plus the API client to manually create log entries from within your infra block.
So, maybe something like:
from prefect.context import FlowRunContext
from prefect import get_client, get_run_logger
from prefect.logging import
# then, in your `run` method
client = get_client()
flow_run_id = self.env["PREFECT__FLOW_RUN_ID"]
flow_run = client.read_flow_run(flow_run_id)
flow = client.read_flow(flow_run.flow_id)
# make a 'fake' flow run context to pass to get_run_logger
context = FlowRunContext(flow=flow, flow_run=flow_run)
logger = get_run_logger(context)
That's just from memory - I haven't tried it. I think it'll give you a logger attached to the flow run. In general, messing around with contexts manually isn't a good idea, but if you've made your own infra block it's probably okay. But YMMV, and use at your own risk, of course. 🙂
You could also just get the flow run ID and then use the client's create_logs call to add log entries to the flow run, but then you won't get any of the log formatting the logger normally applies.
This doesn't quite get you the agent logs you mentioned, but it sounds like the logs from inside the infra block.Michał Augoff
09/20/2023, 8:45 PMrun
so I’ll try to hack around. Thanks for the tip with workers, it might take me some time to migrate but I’ll keep that in mindBring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by