Skip to content
betterstack-alchemyUnofficial

Alerts

An Alert watches one chart on a dashboard, or one saved exploration, and starts an incident when its condition holds: a threshold on the value, a relative change, or an anomaly_rrcf deviation from the predicted value. The incident goes to escalationTarget, your current team by default or an escalation policy, through the alert’s own call, sms, email, push and criticalAlert channels.

Declare the chart, then the alert with the chart’s dashboardId and chartId:

alchemy.run.ts
const app = yield* BetterStack.Telemetry.Source("app-logs", { platform: "http" });
const dashboard = yield* BetterStack.Telemetry.Dashboard("app", { name: "Production app" });
const errors = yield* BetterStack.Telemetry.DashboardChart("errors", {
dashboardId: dashboard.id,
...Chart.line({
name: "Errors",
sql: Chart.timeSeries({ where: `${Chart.json("level")} = 'error'` }),
}),
});

An incident when errors pass 100 in five minutes:

alchemy.run.ts
yield* BetterStack.Telemetry.Alert("error-spike", {
name: "Error spike",
dashboardId: dashboard.id,
chartId: errors.id,
alertType: "threshold",
operator: "higher_than",
value: 100,
sourceVariable: Output.interpolate`source:${app.tableName}`,
aggregationInterval: 300,
checkPeriod: 60,
confirmationPeriod: 300,
recoveryPeriod: 300,
email: true,
});

sourceVariable names the sources the alert runs on, as source: followed by source table names. aggregationInterval, checkPeriod, confirmationPeriod and recoveryPeriod are in seconds.

An alert on a saved exploration takes explorationId instead. paused: true keeps it from checking until you turn it on:

alchemy.run.ts
const rate = yield* BetterStack.Telemetry.Exploration("error-rate", {
...Chart.exploration(Chart.line({ sql: Chart.timeSeries() })),
});
yield* BetterStack.Telemetry.Alert("rate", {
explorationId: rate.id,
alertType: "threshold",
operator: "higher_than",
value: 1000,
checkPeriod: 60,
paused: true,
});

An alert watches exactly one chart or one exploration. dashboardId, chartId and explorationId are create-only: changing one replaces the alert.