Skip to content

Setup Slack Alerts

Logfire allows you to send alerts via Slack based upon the configured alert criteria.

Creating a Slack Incoming Webhook

Logfire uses Slack’s Incoming Webhooks feature to send alerts.

The Incoming Webhooks Slack docs has all the details on setting up and using incoming webhooks.

For brevity, here’s a list of steps you will need to perform:

  1. In your Slack Workspace, create or identify a channel where you want to send Logfire alerts.
  2. Create a new Slack app (or use an existing one) by navigating to https://api.slack.com/apps/new. Give this a meaningful name such as “Logfire Alerts” or similar so you can identify it later.
  3. In the Apps Management Dashboard, Underneath the Features heading on the side bar, select Incoming Webhooks
  4. Click on the Add New Webhook button. This will guide you to a page where you select the channel you want to send alerts to.
  5. Click the Allow button. You will be redirected back to the Incoming Webhooks page, and in the list, you will see your new Webhook URL. This will be a URL that looks similar to something like this:
https://hooks.slack.com/services/...
  1. Copy that somewhere, and save it for the next step

Creating an Alert

There are a few ways to create an alert. You can:

Define alert

We’ll create an alert that will let us know if any HTTP request takes longer than a second to execute.

  • Login to Logfire and navigate to your project

  • Click on Alerts in the Notify section of the left sidebar

  • Select the New alert button in the top right, then pick Custom query

  • Let’s give this Alert a name of Slow Requests

  • For the query, we’ll group results by the http path and duration. We want to include the max duration in a given time frame. We also want to filter out any traces that aren’t http requests, and order by the max duration, so we can see which routes are the slowest. This query looks like:

    SELECT
        max(duration),
        attributes->>'http.route'
    FROM
        records
    WHERE
        duration > 1
        AND attributes->>'http.route' IS NOT NULL
    GROUP BY
        attributes->>'http.route'
    ORDER BY
      max(duration) desc
    
  • Click Preview query results and make sure you get some results back. If your service is lightning fast, firstly congratulations! Secondly try adjust the duration cutoff to something smaller, like duration > 0.1 (i.e, any requests taking longer than 100ms).

    !

  • You can adjust when alerts are sent under the When this alert fires section. With this style of alert, we just want to know if anything within the last 5 minutes has been slow. So we can use the following options:

    • Fire when: the query has any results
    • Look at rows from: the last 5 minutes
    • Check every: 5 minutes

    !

Send Alert to a Slack Channel

Our alert is almost done, let’s send it to a slack channel.

For this, you will need the Webhook URL you created & copied from the Slack Apps Management Dashboard.

Let’s set up a channel, then test that alerts can be sent with the URL. In the Send notifications to section of the alert form:

  • Select Add channel to open the New channel dialog (channels can also be managed from DeliveryChannels in the Notify section of the left sidebar; they are shared across all projects in your organization)

  • Put in a name such as Logfire Alerts. This does not need to be the name of your Slack channel

  • Select Slack Webhook as the type (or leave it as Auto; the Slack format is inferred from hooks.slack.com URLs)

  • Paste in your Webhook URL from the Slack Apps Management Dashboard

  • Click on Send a test alert and check that you can see the alert in Slack. A successful test is required before you can create the channel

  • Click Create channel to create the channel and close the dialog

  • Click the checkbox next to your new channel to select it

    !

Once your Slack channel is connected, click Create alert to save all your changes. Your alert is now live!

You will now receive notifications within your slack channel when the alert is triggered!