> ## Documentation Index
> Fetch the complete documentation index at: https://sariva.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# App logs & pod health

> Let Sariva read your app's logs for error patterns (CloudWatch Logs or New Relic — your platform team approves it per app) and watch your pods for restarts, including across AWS accounts.

Two of the per-app [alert](https://sariva.mintlify.site/concepts/alerting.md) conditions read from outside Kafka:

* **`alert_on_error_pattern`** — Sariva scans your app's **logs** for patterns you specify, from the **one log source your install has**: AWS CloudWatch Logs or New Relic (ask your operator which; see [Which log source your install has](#which-log-source-your-install-has)).
* **`alert_on_pod_restart`** — Sariva checks your app's **EKS pods** for restarts.

Both are opt-in per app. Log scanning additionally needs your **platform team's approval** for your app before anything is read — see [Approval](#approval--your-platform-team-switches-scanning-on).

> [!NOTE]
>
> **Where do lag and metrics come from, then?** Consumer **lag** and throughput come from your Kafka metrics source (the Confluent Cloud Metrics API) — **not** from logs. The log source is used only for **log evidence** (error patterns); pod health comes from the Kubernetes API — the things Kafka itself can't tell you.

## Error-pattern alerts

**What it does.** On an interval your platform team approves (every 5 minutes by default — 1, 5 or 15), Sariva runs **one query** against your app's logs counting matches for every pattern over a window of the same length, so each line is read once. On a match it alerts, and includes the matching log lines as evidence. In chat, *"what's in payments-consumer's logs?"* reads the same way, on demand.

**Enable it** — at [registration](https://sariva.mintlify.site/app-teams/register.md), provide:

* `log_locator` — **where** your app's logs are, as field/value pairs for your install's source:
  * CloudWatch: `{"log_group": "/aws/eks/prod/payments-consumer"}` (the legacy spelling `cloudwatch_log_group` is still accepted for one release and means the same thing).
  * New Relic: the attributes that select your app's lines in `FROM Log`, e.g. `{"container_name": "payments-consumer", "namespace_name": "payments"}` — Sariva builds the `WHERE` clause; you never write NRQL.
* `alert_on_error_pattern` — the pattern(s) to watch, e.g. `ERROR`, `connection pool exhausted`. On CloudWatch each is a Logs Insights `like /…/` (substring or regex); on New Relic each is an RE2 regular expression. **Optional:** with none set, Sariva searches the **common error words** — `ERROR`, `Exception`, `FATAL`, `Traceback`, any case — and every reply says so (*"common error words; set error patterns to sharpen"*). A JSON line that has a `level` field is read by its level instead: `error`, `fatal` or `critical` (any case) is an error, anything else is not, so a clean line such as `{"event": "stats", "errors": 0, "level": "info"}` never counts. The words apply to lines with no `level` field, such as plain-text librdkafka output. A numeric level (pino's `50`) is not read as an error; set your own patterns for such an app. Producer failures (authentication, topic authorization, record too large, brokers unreachable) are searched on every line. Your own patterns are used exactly as written, on every line.

  **Change them in chat:** *"also watch payments-consumer for Timeout and OOM"*, *"stop watching for FATAL"* or *"watch it only for Timeout"*. Sariva shows the whole new list once and saves it on your *yes*, the same as a `PUT`. No new approval is needed, because a read is still one query. The app's channel and the approvals channel are told who changed it. Words you add in chat match **any case** (the confirm says so); patterns set over the API stay exactly as written. If you drop a word from the common set, the rest keep matching in any case.
* `monitor_errors: true` — **ask for scheduled monitoring**. Patterns alone never turn it on: without this setting your patterns sharpen on-demand chat scans only.

**What happens next.** Registering with `monitor_errors: true` and a log location records a **request** for scheduled monitoring (`monitor_state: "requested"` in the response) — nothing is read until your platform team approves it, below. You can also ask in chat — *"alert me when payments-consumer logs errors"*, *"watch its logs for errors"* — which posts the same request.

## How far back Sariva looks

An on-demand read in chat covers the period **you name**, read the way you said it:

* *"what errors did payments-consumer throw in the **last 2 hours**?"* — the last 120 minutes, ending now.
* *"**since 9am**"* — from 09:00 today until now.
* *"**between 2 and 3pm yesterday**"*, *"yesterday afternoon"* — a window that ends in the past is read as asked (CloudWatch `startTime`/`endTime`, New Relic `SINCE … UNTIL …`).
* Follow-ups continue the thread: *"**go back further**"* reads twice the last period, *"**and before that?**"* the same length ending where the last read began, *"what about the **last day**?"* the last 24 hours.
* Say nothing about time and Sariva reads the **last 30 minutes**.

The reply names the period it covered (*last 2 h*, *14:00–15:00 UTC on 2026-10-27*) and, when it found lines, when they were first and last seen inside it. A longer window never means more sample lines — the same handful of verbatim lines is shown — and every read counts once toward your app's daily limit. If you ask for more than your app's approved **look-back** allows, Sariva reads up to the cap and says so: *You asked for the last 3 day(s); your platform team capped this app's look-back at 24 h, so I read the last 24 h.* The time words are read by the model, not by a pattern list, so phrase it however you like. Scheduled monitoring is unaffected: it keeps reading at its approved interval over a window of the same length.

## Approval — your platform team switches scanning on

Log scanning costs money on your log provider's bill at scale, so Sariva reads no app's logs until a platform SRE says so — and there are **two separate things to approve per app**. One never grants the other, each is its own post in the SRE channel, and every cap is set by the SRE at approval; there is no install-wide default. The SRE channel is the install's **approvals channel** (`TEAMS_APPROVALS_CHANNEL_ID` in Teams, `notifications.slack.approval_channel` or `SLACK_APPROVAL_CHANNEL` in Slack), or its alerts channel when no approvals channel is set; budget warnings and cap pauses go there too. Anyone who can reply in that channel may approve or deny for now.

**On-demand log scans** — the reads Sariva makes when someone asks about your app's logs in chat.

1. The first time anyone asks (*"why is payments-consumer throwing errors?"*), Sariva answers what it can read (lag, consumer-group state), says *log scanning isn't enabled for this app, I've asked your platform team*, and posts **one** request: *payments-consumer asks for on-demand log scans. Suggest: look-back up to 24 h, 50 scans/day. Reply approve / approve, lookback 72h, limit 100 / deny.* A repeat ask never re-posts.
2. An SRE replies in that post's thread: **approve** (the suggested caps), **approve, lookback 72h, limit 100** (their own), or **deny**. They can ask *"why?"* or *"what will this cost?"* first — the request keeps waiting; a value that belongs to the other feature (*"every 15 minutes"*) is answered, never applied.
3. Sariva tells the thread that asked and offers to read the logs right then (*"yes"* runs the read). On deny it says so, and a later ask hears *declined*, never "no errors".

On-demand scans need no error patterns: with none set, the read searches the common error words above.

Once approved, every read is bounded by the **look-back**: ask for the last five days on a 72-hour cap and Sariva reads 72 hours and says so. Every read counts toward the **daily limit**; at the limit Sariva says so, reads again tomorrow, and offers to ask your platform team to raise it — *"yes"* posts one raise request (one a day per app), which the SRE answers with *approve* / *approve, limit 100* / *deny*.

**Scheduled monitoring** — the background scan that drives error-pattern alerts.

1. Asking for it — `monitor_errors: true` (register, or `PUT` later) with a log location, or a chat ask — posts **one** request: *payments-consumer asks for scheduled error monitoring: 3 patterns every 5 min, est. 0.5 GB/day, suggest cap 20 GB/month. Reply approve / approve, every 15 min, cap 50 GB / deny.* The estimate is honest — this period's usage where there is some, otherwise an assumed 20 MB of log lines an hour — and the suggested cap is four times it, rounded up (GB per month on CloudWatch, queries per day on New Relic).
2. An SRE replies **approve**, **approve, every 15 min, cap 50** (1, 5 or 15 minutes; any cap), or **deny**. Off-script replies work the same way as above.
3. On approve the engine reads your app's logs at that interval, all patterns in one query, under that cap. The approval is told to the thread that asked **and** to your app's own channel, where its error alerts land.

Changed your mind before the SRE answers? Say *"actually, cancel that"* in the same chat, or `PUT` `monitor_errors: false` — the waiting request is withdrawn (no confirm) and the SRE's post says so; an approve after that is refused.

The states on `GET /api/v1/apps/{alias}` (with `monitor_errors`, and who approved each feature — `chat_scan_approved_by` / `monitor_approved_by` hold the approver's display name, the `*_approved_by_id` fields their chat user id): `chat_scan_state` is `requested`, `approved` or `denied`, with `chat_scan_max_lookback_h` and `chat_scan_daily_limit`; `monitor_state` is `requested`, `approved`, `denied` or `paused`, with `monitor_interval_min`, `monitor_cap` and `monitor_cap_unit`. An unapproved, denied or paused feature reads as *not configured* for that feature — never as "clean".

## What's on, and turning it off

**The list.** In chat, *"which apps have log scanning on?"* or *"what's being monitored?"* gets a list Sariva writes from the live registry — each app, each feature that is on, today's scans against the limit, and who approved it and when. With nothing on it says *No app has log scanning or monitoring on*. Over REST: `GET /api/v1/log-scanning` returns the same rows (`source`, `apps`, and the plain-text `text`).

**Turning it off.** *"Stop monitoring payments-consumer"* (or *"turn off chat scans for payments-consumer"*) gets **one** *"are you sure?"* — *"why?"* is answered and it keeps waiting; *"yes"* turns it off, *"no"* keeps it. Off means it stops until someone asks again and an SRE approves again (turning monitoring off also sets `monitor_errors: false`). Your app's channel and the thread that first asked for it are told. Asking to turn off something that isn't on says so. Over REST, `POST /api/v1/log-scanning/{alias}/turn-off` with `{"feature": "monitor"}` or `{"feature": "chat"}` turns it off with no confirm (`409` when it isn't on, `404` for an unknown app). Anyone authenticated may turn it off for now.

## Budget — what the caps allow per period

**Per app.** Scheduled monitoring runs under the cap the SRE set: at **80%** Sariva warns your app's chat thread; at **100%** it **pauses that app's monitoring only** (`monitor_state: "paused"`), tells your thread and the SRE channel, and resumes on its own when the next period starts (a month on CloudWatch, a day on New Relic). On-demand scans have the look-back and daily limit above.

**Whole install (optional).** Your platform team may also set `LOG_SCAN_BUDGET` in the setup wizard — GB scanned per month on CloudWatch (read from each query's own statistics), queries per day on New Relic. Blank is the default: usage is tracked and nothing is ever paused by it. Set, it warns the SRE channel at 80% and pauses every app's monitoring at 100% until next period; approvals and caps are kept. Usage per app, both states and both caps are on `GET /api/v1/health` (`log_scanning`) and in `sariva validate logs` — on a VM, run it on the host from the install folder: it reads usage and the field checks from the running platform over REST at `http://localhost:8000` with `SARIVA_PLATFORM_API_KEY` from `./.env` (no `docker exec`; `--api-url https://<your-host>` checks another host). If the platform is restarting it waits a few seconds, then says Sariva is still starting.

## Which log source your install has

One per install, chosen in the [setup wizard](https://sariva.mintlify.site/install-setup/wizard.md#step-15--log-source): **CloudWatch Logs**, **New Relic**, or **none**. With none, Sariva says plainly that it cannot read application logs — its capability card, greetings and declines all say so — and nothing on the registration enables it. `sariva validate logs` shows the source and makes one test read.

> [tab] CloudWatch Logs
>
> **Prerequisites:**
>
> * Your app's logs must actually be in the log group you register — see the next section.
> * The Sariva platform needs permission to run Logs Insights queries on that log group — on EKS via [pod AWS identity](https://sariva.mintlify.site/install-setup/irsa.md); on a VM via the instance role ([VM path](https://sariva.mintlify.site/deploy/vm-docker-cc.md#log-scanning-on-a-vm)).
>
> ### Getting logs into CloudWatch (prerequisite)
>
> Sariva **reads** logs; shipping them into CloudWatch is your platform's job, with whatever shipper you already run — a Fluent Bit or OpenTelemetry DaemonSet, the CloudWatch agent, or a logging-library appender that writes to CloudWatch Logs directly. What Sariva needs from the result is simple:
>
> * **One log group it can be pointed at** — the name you register in `log_locator` as `log_group`.
> * **Know that the pattern scan covers the whole group.** Sariva's Logs Insights query filters on message content only (`filter @message like /<pattern>/`), so *everything* in the group counts toward your app's patterns. A **dedicated log group per app** keeps pattern alerts app-scoped; a shared group works, but every app in it is in scope of every pattern — and every byte of it counts against the install's budget.
> * Plain-text lines match fine; structured/JSON logs keep patterns precise — the Python client config Sariva generates uses a structlog JSON renderer for exactly this.
>
> #### Worked example: the CloudWatch Observability EKS add-on
>
> If your cluster ships nothing today, the lowest-friction start on EKS is AWS's own add-on, which runs Fluent Bit and collects container logs from **all pods** by default ([AWS docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Observability-EKS-addon.html)):
>
> ```bash theme={null}
> # 1. The agent needs CloudWatchAgentServerPolicy on the node role
> #    (or pass --service-account-role-arn instead):
> aws iam attach-role-policy \
>   --role-name <your-node-role> \
>   --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
>
> # 2. Install the add-on:
> aws eks create-addon --addon-name amazon-cloudwatch-observability \
>   --cluster-name <your-cluster>
> ```
>
> Application container logs then land in **`/aws/containerinsights/<your-cluster>/application`** — register that name as your `log_group`. Because that group is shared by every pod in the cluster, treat it as a starting point: when pattern noise from other apps (or the scanned volume) becomes a problem, move to per-app log groups via your own shipper configuration (the add-on supports a custom Fluent Bit configuration) and update the app's `log_locator` with `PUT /api/v1/apps/{alias}`.
>
> #### If your app runs on a Docker host instead of Kubernetes
>
> Error-pattern scanning works the same way when the Sariva platform runs on the [EC2 VM path](https://sariva.mintlify.site/deploy/vm-docker-cc.md#log-scanning-on-a-vm) — the registration still just needs `log_locator` + `alert_on_error_pattern`. Ship your container's stdout however you already do; the Docker **`awslogs` log driver** is one ready-made way (a per-container `logging:` block that writes straight to a CloudWatch group using the host's instance role), not the required one — any agent that lands your lines in a log group works. Pod health is different: with no Kubernetes there are no pods, and the health endpoint reports that dimension **NotApplicable** (see below) — log scanning and lag alerts are unaffected.

> [tab] New Relic
>
> **Prerequisites:**
>
> * Your app's logs are in the New Relic account the install was set up with — shipped by whatever you already run (the New Relic infrastructure agent, the Kubernetes integration, Fluent Bit's New Relic output, an APM agent's logs-in-context). Sariva only **reads**.
> * The install carries a read-only **User API key** for that account; the platform team set it up from the [New Relic](https://sariva.mintlify.site/prerequisites/log-sources/newrelic.md) page.
>
> **Point Sariva at your lines.** `log_locator` is the set of log attributes that select your app in `FROM Log` — the same ones you would type into the Logs UI's filter bar: for a Kubernetes workload typically `container_name` + `namespace_name` (or `cluster_name`); for a host process `hostname` + `service_name`; for logs-in-context `entity.name`. Check in the Logs UI that the filter returns only your app's lines: everything it returns counts toward your patterns and the install's daily query budget.
>
> ```json theme={null}
> "log_locator": {"container_name": "payments-consumer", "namespace_name": "payments"},
> "alert_on_error_pattern": ["ERROR", "connection pool exhausted", "timeout"]
> ```
>
> Patterns are RE2 regular expressions (`RLIKE`); a plain word matches as a substring. Sariva runs one NRQL per scan with all your patterns, and a sample query for the evidence lines an alert or a chat answer shows.

## Pod-restart alerts (EKS)

**What it does.** Each tick, Sariva reads the status of your app's pods (scoped to the namespace you register) and alerts when a pod's restart count increases.

**Enable it** — provide at registration:

* `eks_cluster_name`, `k8s_namespace`, `k8s_pod_label_selector`
* `alert_on_pod_restart: true`

**Prerequisites:** the Sariva platform pod needs read access to that cluster/namespace via [pod AWS identity](https://sariva.mintlify.site/install-setup/irsa.md). Access is **namespace-scoped**, never cluster-wide.

## What pod health means when there is no Kubernetes

The pod dimension exists only for an app that actually runs on EKS — `infra_type: "aws_eks"` at [registration](https://sariva.mintlify.site/app-teams/register.md). An app registered with `infra_type: "ec2"` or `"other"` (the **default** on a [VM-shape platform](https://sariva.mintlify.site/deploy/vm-docker-cc.md), since 0.5.127) has no pods to read, and `GET /api/v1/apps/{alias}/health` reports the dimension as **NotApplicable** — not an error, and it does **not** sink the overall status to `unknown`. The verdict then composes from the dimensions that do exist: an active alert (lag, error patterns, rebalances) marks the app degraded or unhealthy; a monitored app with nothing active reads healthy.

An `aws_eks` app whose pods **can't be read** (missing fields, denied access) is different — that dimension exists and stays `unknown`, which honestly caps the verdict. An app registered before 0.5.127 against a VM-shape platform kept the old `aws_eks` default; move it with `PUT /api/v1/apps/{alias}` `{"infra_type": "other"}`.

## Pod resource headroom (metrics-server)

Sariva can also report a pod's **CPU/memory headroom** (live usage vs limits) on demand — e.g. *"does payments-consumer have headroom?"*. This reads the `metrics.k8s.io` API, served by [metrics-server](https://github.com/kubernetes-sigs/metrics-server), which is **not** installed on EKS by default.

**Prerequisite:** install metrics-server on the cluster your app runs in — cleanest is the **EKS managed add-on** (EKS Console → cluster → **Add-ons** → metrics-server, or `aws eks create-addon --cluster-name <cluster> --addon-name metrics-server --region <region>`, or `- name: metrics-server` in an eksctl config). Pair it with the optional `metrics.k8s.io` read rule on the reader/RBAC role — see [Cross-account reader setup](https://sariva.mintlify.site/install-setup/cross-account-reader.md).

**At registration**, set `eks_cluster_name`, `k8s_namespace`, and `k8s_pod_label_selector` so Sariva can locate the pods — the same three fields power both on-demand pod-health (*"is my pod healthy?"*) and headroom questions. For an app in a different AWS account, also set the cross-account fields described below.

Without metrics-server, pod status / restarts / events still work; only headroom degrades to **"live usage unavailable."**

## When your app runs in a different AWS account

If your app's CloudWatch logs or pods live in a **different AWS account** than the Sariva platform, you create a **read-only reader role** in that account and tell Sariva its ARN. Sariva then `sts:AssumeRole`s into it before reading your CloudWatch logs and pod health; for a same-account app it uses its home identity unchanged. (A New Relic log source has no AWS account to cross — the account id and key the install carries select the logs.)

You provide one field at registration:

* **`cross_account_reader_role_arn`** — the ARN of the reader role you author in the app's account. Pair it with `aws_region` and `eks_cluster_name` so Sariva targets the right cluster.

Sariva keys the assume-role on this **explicit ARN** — the role can be named whatever you like; there is no required role name and nothing is derived from `aws_account_id`.

The reader role + its read-only Kubernetes RBAC (trust policy, `eks:DescribeCluster`, scoped `logs:StartQuery`, and the namespace-scoped pod `Role`) are **customer-authored** — Sariva ships no infrastructure-as-code for them. The full copy-paste examples and per-topology guidance live on one page:

> [card] [Cross-account reader setup](https://sariva.mintlify.site/install-setup/cross-account-reader.md)
>
> Trust policy + read-only IAM permissions + namespace-scoped Kubernetes RBAC, with Shape A/B/C guidance and a failure-mode table. Author once per target account.

> [!WARNING]
>
> Sariva never gets cluster-wide or write access to your application cluster. Cross-account access is a **read-only**, **namespace-scoped** role you create and can inspect before applying. A denied or missing grant **fails closed** (empty logs / `phase=Unknown` with a reason) — never a 500, and never a stall for your other apps. The reason is named in the reply: on CloudWatch, *check the reader role's IAM*; on New Relic, *the User API key was rejected or lacks query permission — check `NEWRELIC_API_KEY`*.

## Permissions summary

| Feature | Same account as Sariva | Different account |
| - | - | - |
| Error-pattern (CloudWatch Logs) | Logs Insights read on the log group, via pod AWS identity (EKS) or the instance role (VM) | + STS assume-role into the reader role you authored in the app's account |
| Error-pattern (New Relic) | The install's read-only User API key for the account (`NEWRELIC_API_KEY`) | n/a — one New Relic account per install |
| Pod-restart (EKS) | Namespace-scoped read, via pod AWS identity | + STS assume-role into the reader role + cluster access entry + namespace-scoped RBAC |
| Pod headroom (CPU/mem) | metrics-server on the cluster + `metrics.k8s.io` read in the RBAC role | + same, on the app's cluster + STS assume-role |

The AWS rows require [pod AWS identity](https://sariva.mintlify.site/install-setup/irsa.md) on the Sariva platform pod; every log read additionally requires the app's scanning to be **approved**.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.