Skip to content
betterstack-alchemyUnofficial

Integrations

Better Stack incidents don’t only come from its own monitors and heartbeats. An incoming integration gives another tool somewhere to send its alerts, a secret webhook URL or an e-mail address, and turns them into incidents. An outgoing integration sends Better Stack’s incidents somewhere else. Each is a resource; every prop updates in place except teamId, which replaces the integration and, for an incoming one, gives it a new URL.

Most integrations need a paid plan: their live tests are gated, and the take-over and e-mail ones are tested against the offline mock only. See Compatibility.

Each of these gives you a secret URL (Redacted) to paste into the other tool:

Resource Gives you Where it goes
GrafanaIntegration webhookUrl a Grafana Webhook contact point
PrometheusIntegration webhookUrl an Alertmanager receiver’s webhook_configs
DatadogIntegration webhookUrl a webhook in Datadog’s Webhooks integration
NewRelicIntegration webhookUrl a New Relic Webhook destination
ElasticIntegration webhookUrl a Kibana Webhook connector
AzureIntegration webhookUrl a Webhook action in an Azure Monitor action group
GoogleMonitoringIntegration webhookUrl a Google Cloud Monitoring Webhooks notification channel
AwsCloudWatchIntegration webhookUrl an HTTPS subscription on the SNS topic your alarms notify
AmazonSnsIntegration url an HTTPS subscription on an SNS topic, with rules over the message
IncomingWebhookIntegration url any tool that can send an HTTP request, with your own rules
IncomingEmailIntegration emailAddress any tool that sends alert e-mails

Create one with the policy that should handle its incidents:

alchemy.run.ts
const grafana = yield* BetterStack.Incidents.GrafanaIntegration("grafana", {
name: "Grafana alerts",
escalationPolicyId: policy.id,
});

Without an escalation policy, the integration’s own call, sms, email, push and criticalAlert settings decide how the current on-call person is alerted.

The URL is a secret. Export it from the stack and paste it into the other tool, or pass it to whatever provisions that tool:

alchemy.run.ts
return { grafanaWebhookUrl: grafana.webhookUrl };

Datadog and New Relic integrations take alertingRule: only alerts, or alerts and warnings:

alchemy.run.ts
yield* BetterStack.Incidents.DatadogIntegration("datadog", {
name: "Datadog alerts",
escalationPolicyId: policy.id,
alertingRule: "alert_and_warn",
});

Every incoming integration also takes paused: true, to stop opening incidents during maintenance.

Resource Sends incidents to
OutgoingPagerDutyIntegration a PagerDuty service, through its Events API V2 routing key
SplunkOnCallIntegration Splunk On-Call’s REST endpoint url
OutgoingWebhookIntegration your own url, on incident, on-call or monitor changes
OutgoingEmailIntegration addresses outside Better Stack, with templates per stage

PagerDuty gets incidents with the severity you choose. With notifyAlongsidePrimaryResponder, incidents without an escalation policy reach it too; with a policy, only a step that notifies the integration does:

alchemy.run.ts
yield* BetterStack.Incidents.OutgoingPagerDutyIntegration("pagerduty", {
name: "PagerDuty (payments)",
key: yield* Config.Redacted("PAGERDUTY_ROUTING_KEY"),
severity: "critical",
notifyAlongsidePrimaryResponder: true,
});

An outgoing webhook sends the incident as JSON, or your own body through customWebhookTemplateAttributes. triggerType replaces the integration:

alchemy.run.ts
yield* BetterStack.Incidents.OutgoingWebhookIntegration("ops-hook", {
name: "Incidents to ops tooling",
url: "https://ops.example.com/hooks/better-stack",
triggerType: "incident_change",
onIncidentStarted: true,
onIncidentResolved: true,
onIncidentAcknowledged: false,
onIncidentReopened: false,
onIncidentComment: false,
});

Jira and Linear: connect first, then configure

Section titled “Jira and Linear: connect first, then configure”

A Jira or Linear integration is connected with OAuth in the Better Stack web app, so the API can’t create or delete one. Connect it once, then name it by integrationId: deploying configures it, and destroying only forgets it.

alchemy.run.ts
yield* BetterStack.Incidents.JiraIntegration("jira", {
integrationId: "12345",
automaticIssueCreation: true,
jiraProjectKey: "OPS",
jiraIssueTypeId: "10004",
});

Deploying fails when no integration has that id.

Incidents.CreateIncident opens a manual incident from a running Service. Incidents.AcknowledgeIncident and Incidents.ResolveIncident move it along. They need an API token, which you pass explicitly; use a team-scoped Uptime API token:

src/api.ts
import * as BetterStack from "betterstack-alchemy";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { Box } from "./shared.ts";
const IncidentsToken = BetterStack.apiTokenFromConfig("BETTERSTACK_INCIDENTS_TOKEN");
export default class Api extends BetterStack.Cloud.Service<Api>()(
"Api",
{ server: Box, main: import.meta.url, port: 3000 },
Effect.gen(function* () {
const openIncident = yield* BetterStack.Incidents.CreateIncident(IncidentsToken);
return {
fetch: Effect.gen(function* () {
const incident = yield* openIncident({
summary: "Payments are failing",
requesterEmail: "oncall@example.com",
email: true,
});
return yield* HttpServerResponse.json({ id: incident.id });
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(BetterStack.Incidents.CreateIncidentHttp)),
) {}

Opening an incident alerts the on-call team through the channels the request turns on. These bindings are tested against the offline mock only.