# Sentry metric alert notifications on your phone

> Get a push notification when a Sentry metric alert (error rate, latency, crash-free sessions, …) goes critical, warning, or resolves.

- Company: Sentry (https://www.justpush.io/recipes/sentry)
- Event: `metric_alert` (Metric alert)
- Tags: Developer tools, Monitoring
- Install: https://studio.justpush.io/recipes/sentry/metric-alert
- Web page: https://www.justpush.io/recipes/sentry/metric-alert

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In Sentry, go to Settings > Developer Settings > Custom Integrations and create an Internal Integration.
3. Paste your webhook URL (shown in Studio after install) as the Webhook URL and follow the setup notes below for Metric alert.
4. Save the integration.
5. In your internal integration (**Settings → Developer Settings → Custom Integrations**), turn on **Alert Rule Action** and save.
6. Then open a metric alert rule and, for its **Critical** and **Warning** thresholds, add the action **Send a notification via _your integration_**. Sentry also sends the resolved notification to the same action.
7. Sentry signs each request with a `Sentry-Hook-Signature` header, but JustPush doesn't check it yet, so keep your endpoint URL private.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Sentry → metric alert
// Fires when a Sentry metric alert (error rate, latency, crash-free rate, …) goes
// critical, warning, or back to resolved.
// Docs: https://docs.sentry.io/organization/integrations/integration-platform/webhooks/metric-alerts/

// Each state, how to label it, and how loud to be.
const STATES = {
    critical: { emoji: "🔴", priority: 1 },
    warning: { emoji: "🟠", priority: 0 },
    resolved: { emoji: "✅", priority: -1 },
}

// Only link to real http(s) URLs.
function link(url, cta) {
    return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
}

function handleRequest(request) {
    const body = request.body || {}
    const alert = body.data?.metric_alert

    // Guard: only metric alerts, so other Sentry webhooks on this integration stay quiet.
    if (!alert || !Object.prototype.hasOwnProperty.call(STATES, body.action)) {
        console.log(`Ignoring Sentry "${body.action ?? "unknown"}" webhook — not a metric alert`)
        return null
    }

    const state = STATES[body.action]
    const name = alert.alert_rule?.name ?? alert.title ?? "Metric alert"
    // description_text looks like "1000 events in the last 10 minutes\nFilter: level:error".
    const detail = String(body.data.description_text ?? "")
        .split(/\\n|\n/)
        .map((line) => line.trim())
        .filter(Boolean)
        .join(" · ")

    return {
        title: `${state.emoji} ${body.action === "resolved" ? "Resolved: " : ""}${name}`,
        message: detail || (body.action === "resolved" ? "Back to normal" : `Alert is ${body.action}`),
        topic: "Sentry",
        priority: state.priority,
        buttons: link(body.data.web_url, "View alert"),
    }
}
```

## Sentry metric_alert webhook payload (sample)

```json
{
  "data": {
    "web_url": "https://acme.sentry.io/alerts/rules/details/7/",
    "metric_alert": {
      "id": "4",
      "title": "Sacred Marmot",
      "status": 20,
      "projects": [
        "web"
      ],
      "alert_rule": {
        "id": "7",
        "name": "Too many errors",
        "query": "level:error",
        "dataset": "events",
        "projects": [
          "web"
        ],
        "aggregate": "count()",
        "time_window": 10
      },
      "identifier": "1",
      "date_started": "2026-09-29T08:06:40.000000Z"
    },
    "description_text": "1000 events in the last 10 minutes\nFilter: level:error",
    "description_title": "Critical: Too many errors"
  },
  "actor": {
    "id": "sentry",
    "name": "Sentry",
    "type": "application"
  },
  "action": "critical",
  "installation": {
    "uuid": "a8e5d37a-696c-4c54-adb5-b3f28d64c7de"
  }
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Sentry and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
