<@ULVA73B9P> Is there a comprehensive reference fo...
# ask-marvin
j
@Marvin Is there a comprehensive reference for the hierarchy of Prefect resources that can be referred to in Jinja? I am looking specifically for how to refer to the logs of a flow run but would like to see this in context.
m
The hierarchy for Jinja templating in Prefect resources and the specific reference for accessing logs of a flow run using Jinja are not explicitly stated in the provided documentation. However, from what is available, it is clear that Prefect automatically captures logs for flow and task runs and provides the capability to view and filter these logs in the Prefect UI or Prefect Cloud, as well as access them via the API. To access the logs of a flow run using Jinja in Prefect 2.x, you would typically utilize the capabilities of Prefect's logging feature. Prefect's logging system automatically logs events for flow runs and task runs. Although specific Jinja placeholders for logs are not provided in the excerpts, logs can be custom formatted and configured, indicating there are ways to interact with these logs programmatically. For a comprehensive reference, you can refer to the official Prefect documentation or API. Details on how to use Jinja with Prefect's logs might be found in the documentation section on logging or in the guide for templating with Prefect. If you need more specific guidance, I recommend checking the complete Prefect 2.x documentation or reaching out to Prefect's support for detailed instructions on using Jinja templating to refer to logs within the context of the Prefect resource hierarchy.
n
I don't think you'd be able to directly match on the contents a given flow run's log records in an event trigger if thats what you're asking (besides the final state message) i typically like to look at the raw event in the event feed that I'd like to
match
or
match_related
on to see what's present, e.g. if i wanted the flow run that handled marvin's response above to trigger some automation, i would look at this and maybe match on the contents of the
resource
or
related
resources
j
@Nate, thanks for responding. Great suggestion to check the event feed to get more insight into the resource hierarchy. In this specific case, I am looking to include some additional information in notifications of failures. The default notification message includes flow_run.state.message, which is helpful. In some other cases, there are details from the logs that I would like to pull into the notification email - just INFO level stuff that wouldn't be part of the state message but that I could format in such a way to easily parse it from the full log if I could grab that resource by its ID.
n
i would check out `emit_event` to conditionally emit your own custom event that has a payload containing whatever subset of what you're logging to INFO that's relevant for your notification, and then that event could serve as the trigger of your automation, which could have a
Send a notification
action that parses / jinja templates the event payload as you want it
🙌 1