Integrate Spike with Prefect
Integrate Spike with Prefect to receive real-time alerts via Phone calls, SMS, Slack, MS Teams, and more when a flow run fails or crashes.
Overview
Prefect is a workflow orchestration platform for building, scheduling, and monitoring data pipelines. A Prefect automation can call a webhook when its trigger fires.
With Spike's Prefect integration, an automation that fires opens an incident in Spike. Spike does not auto-resolve Prefect incidents yet: the responder resolves them in Spike.
How it works
Spike reads these fields from the webhook body:
alert_ididentifies one alert: one automation on one flow run. You build it as{{ automation.id }}:{{ event.resource.id }}. Spike uses it to join repeats to the open incident.statusis alwaysTriggered, typed by you as a fixed word in the action. It opens an incident, or joins the open one with the samealert_id. A missing or unknownstatusalso opens an incident, so a broken template still pages.automation,flowandflow_run(the automation name, the flow name and the flow run name) build the title.state_messageis Prefect's sentence about the run's current state. It arrives as a JSON string, ornullwhen Prefect has none.null, an empty string,Noneandnullas text are ignored.state,event,urlandoccurredare shown on the incident. They are never part of the title.
An alert_id is usable when it is a number, or text that is not empty after trimming, has at least one letter or digit, and holds no unexpanded template variable ({{...}}, {%...%}, $name, ${name} or %name%). Two alerts that both arrive with an unexpanded alert_id open two incidents. Without a usable alert_id, Spike matches a repeat by title.
A repeat that changes only state, state_message, event or occurred joins the open incident.
The incident title is the first of these that applies. Whitespace is collapsed.
Usable alert_id and a state_message
{state_message} in {flow}/{flow_run}, with Prefect's state message as it arrived
Otherwise, with an automation
{automation} on {flow}/{flow_run}, for example Nightly ETL still running after 30 minutes on warehouse-etl/crimson-fox. This is the only form used without a usable alert_id, and it never contains state, state_message or occurred.
No automation, but flow or flow_run
Prefect alert on {flow}/{flow_run}
Nothing usable
Prefect alert with no details
If only one of flow and flow_run is present, only that one is used. If both are absent, the "where" is dropped together with its in or on. A value that is an unexpanded template variable, None or null counts as absent. Titles are at most 200 characters: the "where" is kept whole and the first part is cut at a word boundary with .... If the "where" alone is over 100 characters, the title is cut plainly instead.
Set up instructions
Step 1: Create a Prefect integration in the Spike dashboard and copy the webhook URL.
Create integration and service on our dashboardStep 2: Configure the webhook in Prefect.
Create a Webhook block
Log in to Prefect and open Blocks in the left menu.
Click Add Block (the + button) and choose Webhook.
Enter a Block Name, for example
spike.Set Method to
POST.Paste the Spike webhook URL into the Webhook URL field.
In Webhook Headers, enter the JSON below. This is required: Prefect sends the body without a content type, and Spike cannot read it without this header.
Click Create.
Create the Automation
Open Automations and click Add Automation (the + button).
Trigger: choose the trigger for the problem you want to catch, and click Next. For example, a Flow run state trigger that fires when a run stays in a state (such as Running) longer than a set time.
Actions: choose Call a webhook, select the
spikeblock, and paste the payload below into the Payload field. Keep"status": "Triggered".Enter a name for the automation. This name becomes
automationin the incident title, so write it as a sentence, for exampleNightly ETL still running after 30 minutes. Click Save.
All fields are required to be present. alert_id and status decide whether the incident is opened or joined; automation, flow, flow_run and state_message build the title; state, event, url and occurred are shown on the incident.
Write automation, flow, flow_run and state_message exactly as shown, without quotes around them: the tojson filter adds the quotes and escapes any quote or backslash in a name, so the body stays valid JSON (a name such as Nightly "warehouse" ETL late would otherwise break it and Spike would reject the request). For state_message it also writes null when Prefect has no message.
When the automation fires, Prefect sends a body like this:
Spike opens an incident titled Nightly ETL still running after 30 minutes on warehouse-etl/crimson-fox.
Test the integration
Trigger the automation (for example, start a flow run that stays in the trigger's state past its time limit).
Confirm the automation fires and a new incident is created in Spike.
Resolve the incident in Spike once the run is healthy again. Spike does not auto-resolve Prefect incidents.
Last updated

