Event specification
Events adhere to a structured specification.
Name | Type | Required? | Description |
---|---|---|---|
occurred | String | yes | When the event happened |
event | String | yes | Name of the event that happened |
resource | Object | yes | Primary resource this event concerns |
related | Array | no | List of additional Resources involved in this event |
payload | Object | no | Open-ended set of data describing what happened |
id | String | yes | Client-provided identifier of this event |
follows | String | no | ID of an event that is known to have occurred prior to this one |
Event grammar
Events have a consistent and informative grammar: an event describes a resource and an action it took— or that was taken—on that resource. For example, events emitted by Prefect objects take the form of:Event sources
Prefect objects automatically emit events, including flows, tasks, deployments, work queues, and logs. Prefect-emitted events contain theprefect
or prefect-cloud
resource prefix.
You can also send events to the Prefect
events API through an authenticated HTTP request.
Emit custom events from Python code
The Prefect Python SDK provides anemit_event
function that emits a Prefect event when called. You can call
emit_event
inside or outside of a task or flow. For example, running this code emits an event to Prefect Cloud,
which validates and ingests the event data:
emit_event
two arguments: event
, the name of the event, and resource={"prefect.resource.id": "my_string"}
,
the resource ID.
To get data into an event for use in an automation action, specify a dictionary of values for the payload
parameter.
Emit events through webhooks
Prefect Cloud offers programmable webhooks to receive HTTP requests from other systems and translate them into events within your workspace. Webhooks can emit pre-defined static events, dynamic events that use portions of the incoming HTTP request, or events derived from CloudEvents. Events emitted from any source appear in the event feed, where you can visualize activity in context and configure automations to react to the presence or absence of events in the future.Resources
Every event has a primary resource, which describes the object that emitted an event. Resources are used as quasi-stable identifiers for sources of events, and are constructed as dot-delimited strings, for example:Events in the Cloud UI
Prefect Cloud provides an interactive dashboard to analyze and take action on events that occurred in your workspace on the event feed page.
Respond to events
From an event page, you can configure an automation to trigger on the observation of matching events—or a lack of matching events—by clicking the automate button in the overflow menu: