PagerDuty Integration
Step-by-step PagerDuty setup — route critical alerts to on-call engineers, auto-resolve incidents when deploys recover, and manage on-call from the dashboard.
PagerDuty Integration
CodeSpar integrates with PagerDuty to page on-call engineers when critical incidents occur. Build failures, deploy health issues, and high-severity Sentry errors can automatically create PagerDuty incidents. When the issue is resolved (e.g., a rollback succeeds), CodeSpar auto-resolves the PagerDuty incident.
Prerequisites
Before you start, you need:
- PagerDuty account with at least one service configured
- PagerDuty API v2 token with write access (Account Settings > API Access Keys)
- Service ID — the PagerDuty service that will receive incidents
- Escalation Policy ID — the escalation policy for routing alerts
- From email — a valid email address associated with your PagerDuty account (required by the API for incident creation)
Configuration
Set the following environment variables in your CodeSpar instance:
Finding Your Service ID and Escalation Policy ID
- Service ID: Go to PagerDuty > Services > select your service > the URL contains the ID:
https://acme.pagerduty.com/services/P1ABC2D - Escalation Policy ID: Go to PagerDuty > Escalation Policies > select the policy > URL:
https://acme.pagerduty.com/escalation_policies/PABCDEF
Environment Variable Reference
| Variable | Required | Default | Description |
|---|---|---|---|
PAGERDUTY_API_TOKEN | Yes | — | PagerDuty API v2 token |
PAGERDUTY_FROM_EMAIL | Yes | — | Email for the From header (must be a valid PD user) |
PAGERDUTY_SERVICE_ID | Yes | — | PagerDuty service to receive incidents |
PAGERDUTY_ESCALATION_POLICY_ID | Yes | — | Escalation policy for routing |
PAGERDUTY_ENABLED | No | true | Toggle integration on/off |
PAGERDUTY_AUTO_RESOLVE | No | true | Auto-resolve incidents when issue clears |
PAGERDUTY_SEVERITY_THRESHOLD | No | high | Minimum severity that triggers a page |
PAGERDUTY_DEDUP_KEY_PREFIX | No | codespar | Prefix for PD dedup keys (prevents duplicates) |
What Triggers a PagerDuty Incident
CodeSpar creates a PagerDuty incident when any of these occur and the severity meets the threshold:
| Trigger | Severity | PagerDuty Incident Title |
|---|---|---|
| Deploy health monitor detects critical spike (5x baseline) | critical | [CodeSpar] Critical: acme/backend-api deploy v2.4.1 — error rate 5.8x baseline |
| Deploy health monitor detects sustained error increase | high | [CodeSpar] High: acme/backend-api deploy v2.4.1 — sustained error rate 3.2x baseline |
| New fatal Sentry errors after deploy | critical | [CodeSpar] Critical: acme/backend-api — 3 new fatal Sentry errors post-deploy |
| Build failure on main branch (configurable) | high | [CodeSpar] High: acme/backend-api CI build #349 failed on main |
| Incident Agent escalation | Varies | [CodeSpar] {severity}: acme/backend-api — {incident summary} |
Incident Payload
Each PagerDuty incident includes structured details in the body:
Deduplication
CodeSpar uses PagerDuty's incident_key for deduplication. The key is constructed as:
Examples:
codespar-acme-backend-api-deploy-v2.4.1codespar-acme-backend-api-build-349codespar-acme-backend-api-sentry-ISSUE-123
If multiple alerts fire for the same event, PagerDuty groups them into a single incident.
Auto-Resolve
When PAGERDUTY_AUTO_RESOLVE is true, CodeSpar automatically resolves the PagerDuty incident when:
| Recovery Event | Resolution |
|---|---|
| Deploy confirmed healthy (10/10 checks pass) | Resolves deploy-related incidents |
| Rollback succeeds and health monitor passes | Resolves deploy and Sentry incidents |
| Build passes after a failure on the same branch | Resolves build-related incidents |
Resolution message example:
If PAGERDUTY_AUTO_RESOLVE is false, incidents remain open until manually resolved in PagerDuty.
Dashboard: On-Call and Acknowledgment
The CodeSpar dashboard shows PagerDuty status for each project:
View On-Call
The project overview displays the current on-call engineer pulled from PagerDuty:
Acknowledge from Dashboard
When a PagerDuty incident is triggered, the dashboard shows an acknowledgment button. Clicking it:
- Acknowledges the incident in PagerDuty
- Logs the acknowledgment in the CodeSpar audit trail
- Notifies connected channels that the incident was acknowledged
API Endpoints
Trigger a PagerDuty Incident Manually
Get Current On-Call
Response:
Resolve an Incident
Troubleshooting
Incidents Not Creating
- Verify
PAGERDUTY_API_TOKENis valid — test with:curl -H "Authorization: Token token=YOUR_TOKEN" https://api.pagerduty.com/users/me - Confirm
PAGERDUTY_FROM_EMAILmatches a user in your PagerDuty account - Check that
PAGERDUTY_SERVICE_IDandPAGERDUTY_ESCALATION_POLICY_IDare correct - Verify the alert severity meets
PAGERDUTY_SEVERITY_THRESHOLD - Check server logs for
pagerdutyentries
Incidents Not Auto-Resolving
- Confirm
PAGERDUTY_AUTO_RESOLVEistrue - Verify the
incident_keymatches between creation and resolution - Check that the recovery event actually fired (health monitor passed, build succeeded)
Wrong People Getting Paged
- Review the escalation policy in PagerDuty (not in CodeSpar)
- Verify
PAGERDUTY_ESCALATION_POLICY_IDpoints to the correct policy - Check the on-call schedule in PagerDuty for the correct rotation
Next Steps
- Post-Deploy Health Monitor -- understand what triggers PagerDuty alerts
- Linear Integration -- create tickets for non-urgent issues
- Deploy Pipeline -- set up the full deploy workflow
- Enterprise Integrations -- overview of all integrations