Articles

How to get alerted when your app starts logging errors

Send a signed webhook when runtime error logs cross a threshold, even if the API still returns HTTP 200.

Updated

Your API can return HTTP 200 while its report worker fails every time. An uptime check tells you the API answered; it does not tell you the work succeeded. On Gregale, use log_error_lines to alert when your app writes too many runtime error logs in a time window, without forwarding all your logs to a separate monitoring service.

SignalUse it to detect
Uptime checkThe API is unreachable or fails a health check.
HTTP error rateRequests are returning errors.
Runtime error logsA background operation fails even though the API is still healthy.

Set up an error-log alert on Gregale

Use a disposable Hobby-or-higher test workspace, the Gregale CLI, Bash, curl, jq, and OpenSSL. Download the runnable starter and run the commands from the extracted directory. The sample makes a new public app for the webhook callback. Open ingress only on the new test app, not on an existing service. Its log controls and receipt endpoint require a private demo token. Do not add those controls to a real API.

Set FAAS_TOKEN to a deploy-capable token for that test workspace, then run:

bash
bash drill.sh

The script deploys a fresh app and creates a direct webhook rule that fires at three or more error lines in five minutes. This is a drill threshold, not a recommendation for production. Expect a few minutes for metrics collection and delivery.

What counts as a passing drill

  1. The app logs one warning to initialize the runtime counters at zero errors, followed by four structured info lines. The info messages contain the word “error,” but their level is info. The script waits for an evaluation after that burst and confirms the rule is OK and no automatic webhook was delivered.
  2. The app emits four structured error lines once. The script polls for a signed alert.fired receipt and a non-test delivery for the same rule, delivery ID and observed value. The delivery history must show HTTP 200. Use the app’s own /ready endpoint, not the edge health route, to verify the app still answers.
  3. The script deletes the test rule and app. It prints a timeout if the expected signal never arrives; a failed verification request is reported separately rather than silently retried. The reported counter increase can differ from the number of lines emitted. What matters is whether it crossed the threshold.

A test-delivery button checks webhook connectivity, not whether runtime logs fired your rule.

What we verified on Gregale

We deployed the starter to a disposable app. After the warning and four info lines, the evaluated rule was OK and had no deliveries. After four structured error lines, the receiver verified the signature and recorded an automatic alert.fired with an observed value of four. The app’s own /ready endpoint returned HTTP 200 at the checks before and after the error burst. The drill used a direct webhook receiver, not Slack, PagerDuty, or email.

Keep the receiver safe and clean up

The starter checks the HMAC against the raw request body, checks the signed timestamp and the envelope’s delivery ID, then reads the event from payload and deduplicates by delivery ID in memory. For production, use a durable idempotency store and hand off slow notification work before returning 2xx. See the signature and retry contract. Never put secrets in a webhook URL or print them in app logs. The built-in notification channels are an alternative when you want Slack, PagerDuty, or email without running a receiver.

The script prints a private recovery directory before creating resources. It retains the app creation receipt, rule ID and verification results there, not the tokens. Cleanup runs on normal exit, errors and ordinary interruptions. If the process is killed or cleanup cannot finish, stop the original run before retrying with the same test credential and the recovery directory it printed:

bash
bash drill.sh cleanup /path/to/recovery-directory

Cleanup checks the exact app identity before deleting anything. If a rule deletion cannot be confirmed, it still tries to remove the verified disposable app and reports the rule as unconfirmed. If the app creation response was lost, the script will not delete an app it cannot prove it created. Inspect that case manually using the saved intent. Remove the local recovery directory when you no longer need it.

What this does not tell you

An error-log rule is not a report delivery guarantee. If the job never starts or emits a failure only as info, there may be no error-level line. For schedules that go silent, alert on missed cron runs. This rule counts app-wide runtime lines, not unique requests or distinct errors. Filtering on specific messages or routes is a different log-search alert, where that preview is enabled.

Questions

How can I get an alert when an application logs errors?

On Gregale, create an app-scoped log_error_lines rule and choose a count and time window. Point it at a signed webhook receiver or a supported notification channel.

Does a log alert require the API to return HTTP 500?

No. Runtime error log counts and HTTP status codes are separate signals. A background task can log an error while the API continues to return HTTP 200.

Does the word error in an info log count?

No. Use an error-level runtime record, such as JSON with level set to error. An info record mentioning an error and build logs do not count for this metric.