Skip to content

Sentry — alert on project error-rate spike

After a release Sentry only fires on big incidents. I want to catch a slow error-rate climb over a 15-minute window before it becomes a real incident.

Recipe

bash
#!/usr/bin/env bash
# /opt/sentry-error-rate.sh — runs from cron every 5 min
# Sentry Events API v0 — /api/0/projects/{org}/{proj}/stats/

ORG=${SENTRY_ORG}
PROJ=${SENTRY_PROJECT}
TOKEN=${SENTRY_AUTH_TOKEN}
THRESH=${THRESH:-50}              # events / 15-min bucket

NOW=$(date +%s)
SINCE=$((NOW - 900))               # last 15 min

COUNT=$(curl -s -H "Authorization: Bearer $TOKEN" \
  "https://sentry.io/api/0/projects/$ORG/$PROJ/stats/?since=$SINCE&until=$NOW&resolution=10s&stat=received" \
  | jq '[.[] | .[1]] | add')

if [ "${COUNT:-0}" -gt "$THRESH" ]; then
  echo "sentry-spike: $COUNT events in 15min (threshold $THRESH)"
  curl -fsS -X POST "$HEARTBEAT_URL" \
       -H 'Content-Type: application/json' \
       --data "{\"status\":\"down\",\"detail\":\"$COUNT events / 15m\"}"
  exit 2
fi
echo "OK ($COUNT events / 15m)"

Same thing in Enterno.io

Wrap this script in an Enterno heartbeat — 30-day retention of error-rate alongside uptime in one dashboard instead of Sentry charts that do not correlate with upstream incidents.

Set up API monitor → ← All recipes

Related recipes

The server starts returning 503/504 — but a plain uptime check misses it because the homepage is 200 while the API path is on fire.