Send alerts on failure
Learn how to use automations to notify your team when a flow fails.
In the Debug a data pipeline tutorial, you learned how to troubleshoot failed flow runs. In this tutorial, you’ll learn how to set up an email alert that proactively notifies your team about failures. Alerts let team members engage with the troubleshooting process, even if they don’t typically log into Prefect Cloud.
This tutorial starts where the Set up a platform for data pipelines tutorial leaves off, so complete that one first. You will need a paid Prefect Cloud account.
Set up an automation
Automations are used to set up alerts in Prefect. First, you need to create a new automation.
- Sign in to Prefect Cloud, and use the workspace switcher to open the
staging
workspace. - Go to Automations and then click Add Automation.
Specify the trigger
An automation triggers whenever a specified condition is met.
- Select the Flow run state trigger type.
- Trigger whenever the
data-pipeline
flow has flow runs that enter the Failed or Crashed states. - Click Next to go to the next step.
Specify the action
Once an automation triggers, it can perform one or more actions.
- Choose the Send a notification action type
- In order to send an email notification, you need to create a block.
Blocks store configuration and provide an interface for external systems.
- Under Block, click Add.
- Find the Email block, and then click Create.
- Specify
email-alerts
as the block name, and provide a JSON list of email addresses to send notifications to (e.g.["you@example.com"]
). - Click Create to save the block.
- Click Next to go to the next step.
Save the automation
Give the automation a name and description so that you can identify its purpose later.
- Name:
email-alert
- Description:
Send an email when the 'data-pipeline' flow fails
- Click Save.
You’ve now created an automation that sends an email whenever the data-pipeline
flow in the staging
workspace has a failed run.
Test the alert
To test the alert, you need to trigger a flow run failure in the staging
workspace.
After the script finishes, you should receive an email with details about the failed flow run. The email should look similar to the following:
You can open the URL to view the flow run in Prefect Cloud.
Next steps
In this tutorial, you used Prefect Cloud automations to set up an email alert.
To learn more about automations:
- Read Trigger actions on events to become an automations expert.
- See Python and Terraform examples for creating an automation programmatically.
Need help? Book a meeting with a Prefect Product Advocate to get your questions answered.
Was this page helpful?