Open Spanner
Concepts

Alerts

Watch usage windows against thresholds.

Alerts let Open Spanner watch a meter for threshold crossings. A rule selects a meter, an optional subject, optional dimension filters, a time window, a comparator, and a delivery destination.

For example, an alert can watch api_requests for one endpoint and trigger when the last hour reaches 10,000 requests.

How Alerts Work

An alert rule evaluates the meter's aggregation over a rolling window:

FieldMeaning
MeterThe usage signal to evaluate.
SubjectOptional subject filter, such as one customer or organization.
MetadataOptional dimension filters, such as endpoint=/checkout or plan=enterprise.
WindowHow far back the rule looks during evaluation.
Comparatorgt, gte, lt, lte, eq, or neq.
ThresholdThe value to compare against.
Evaluation intervalHow often the rule should be checked when no new matching usage arrives.
DestinationThe notification target to use when alert state changes. The first supported destination type is webhook.

When usage is reported, Open Spanner finds enabled rules for that meter and only queues rules whose subject and metadata filters match the event. This keeps alert evaluation tied to the relevant usage stream instead of scanning every rule for every event.

States And Events

Each rule has a current state:

StateMeaning
okThe current window is within the configured threshold.
alertingThe current window crosses the threshold.
no_dataNo retained usage matched the rule window.
errorThe last evaluation failed.

Open Spanner records alert events when a rule first enters alerting, resolves back out of alerting, or fails evaluation.

Destinations And Webhooks

Alert destinations hold the webhook URL and signing secret. Rules reference a destination, so multiple thresholds can notify the same endpoint without copying secrets into each rule.

For webhook destinations, the alert worker sends an HTTP POST when a rule creates a triggered or resolved event. The dashboard shows the signing secret only when a destination is created or rotated.

Webhook requests include:

HeaderValue
Content-Typeapplication/json
User-Agentopen-spanner-alert-worker
X-Open-Spanner-TimestampUnix timestamp used for signing.
X-Open-Spanner-Signaturev1=<hex-encoded-hmac-sha256> when the destination has a signing secret.

The signature is computed over:

<timestamp>.<raw_request_body>

Use the destination signing secret to verify the HMAC before trusting the webhook payload.

The webhook payload includes the rule, current state, and event:

{
  "rule": {
    "id": "rule_123",
    "name": "High API traffic",
    "meter": "api_requests",
    "window_seconds": 3600,
    "comparator": "gte",
    "threshold": 10000,
    "destination_id": "dest_123",
    "destination_name": "Primary webhook"
  },
  "state": {
    "status": "alerting",
    "value": 12840,
    "message": "value 12840.0000 gte threshold 10000.0000",
    "evaluated_at": "2026-06-18T20:00:00Z"
  },
  "event": {
    "id": "event_123",
    "rule_id": "rule_123",
    "type": "triggered",
    "value": 12840,
    "message": "value 12840.0000 gte threshold 10000.0000",
    "created_at": "2026-06-18T20:00:00Z"
  }
}

Webhook delivery is best-effort in this version. A failed webhook is logged by the worker; the alert state and alert event are still recorded in Open Spanner.

Worker Process

Alert evaluation runs outside the API process. The API records usage and queues alert work; the alert worker claims queued jobs from the same database and evaluates them.

Run at least one alert worker when alerts are enabled. With Postgres, multiple alert workers can run at the same time because jobs are claimed with row-level locking.

Current Scope

Alerts are visible in the dashboard and full REST API. They are intentionally not part of the generated SDK surface, which stays focused on meters, usage ingestion, querying, and direct exports.

On this page