> ## 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.

# New Relic

> Optional — let Sariva read your apps' logs from New Relic (NRQL over NerdGraph, one read-only User API key) as the install's log source.

ⓘINFO

**Setup wizard → the Log source step (the last one).** An install reads application logs from exactly **one** source — AWS CloudWatch Logs, New Relic, or none — chosen in the wizard. This page is the New Relic side. Whatever the source, Sariva reads no app's logs until a platform SRE **approves** it per app — on-demand chat scans and scheduled monitoring separately, each with caps the SRE sets — and the install may carry an optional **budget** — see [App logs & pod health](https://sariva.mintlify.site/app-teams/logs-and-pod-health.md).

Sariva reads logs with **NRQL** through New Relic's GraphQL API (NerdGraph): one `SELECT … FROM Log WHERE <the app's locator> SINCE <window>` per scan, counting every one of the app's patterns across the app's [log fields](#json-logs--tell-sariva-which-fields-to-search) in that single query, plus one sample query for the evidence lines an alert or a chat answer shows. It authenticates with a **User API key** (`NRAK-…`) sent as the `API-Key` header. Nothing is written to New Relic, and no agent is installed.

## What you need first

* [ ] The **account ID** of the New Relic account your apps' logs land in (shown in the account picker and in the URL of the New Relic UI).
* [ ] Whether that account is in New Relic's **US** or **EU** region — EU accounts are served from `api.eu.newrelic.com`; everything else from `api.newrelic.com`. Pick the wrong one and every read is rejected.
* [ ] A **User API key** of a user who can run NRQL against that account. Create a dedicated user for Sariva with **read-only** access (a *Read only* role in a group that has access to the account — check New Relic's docs for the current UI path under **API keys**; the key type must be *User*, not *Ingest*). The key is shown once; copy it then.
* [ ] Outbound HTTPS from the Sariva platform to `api.newrelic.com` (or `api.eu.newrelic.com`) on 443. `HTTPS_PROXY` / `NO_PROXY` are honoured like every other Sariva client.
* [ ] Your apps' logs already in New Relic — shipped by whatever you run today (the infrastructure agent, the Kubernetes integration, Fluent Bit's New Relic output, APM logs-in-context). Sariva only reads.

## Step 1 — Choose New Relic in the wizard

The wizard's last step asks for the log source:

```
--- Step 15: Log source ---
Which log source should Sariva use?
  [1] AWS CloudWatch Logs
  [2] New Relic
  [3] None — Sariva will say it cannot read application logs
  New Relic account id (the number in the account picker)
  NEWRELIC_ACCOUNT_ID: 1234567
  New Relic region: US or EU
  NEWRELIC_REGION [US]:
  New Relic credentials: set in .env as NEWRELIC_API_KEY.
    NEWRELIC_API_KEY: New Relic USER API key (NRAK-…) of a read-only user — the key itself, or file:///path or env://VAR holding it
  Optional budget for the WHOLE install, in queries per day. Every cap is
  per app and set by the SRE at approval; this one is a safety net on top:
  at 80% Sariva warns the SRE channel, at 100% it pauses every app's
  scheduled monitoring until next period. Blank = no install cap (usage
  still tracked).
  Budget (queries per day):
```

It records the account ID and region, names `NEWRELIC_API_KEY` as the secret to fill, and asks the optional install-wide budget — **NRQL queries per day** (blank = no install cap; usage tracked, every cap per app). On a **VM/Docker** install the wizard writes to `.env`:

```bash theme={null}
LOG_SOURCE=newrelic
NEWRELIC_ACCOUNT_ID=1234567
NEWRELIC_REGION=US
NEWRELIC_API_KEY=REPLACE_ME_NEWRELIC_API_KEY   # fill in the NRAK-… key
LOG_SCAN_BUDGET=                               # optional install cap, e.g. 2000 queries a day; blank = none
```

On a **Kubernetes** install it writes `values.yaml`:

```yaml theme={null}
logSource:
  source: newrelic
  budget: "2000"              # optional install cap in queries per day; "" = none
  newrelic:
    existingSecret: sariva-platform-extras
    accountId: "1234567"
    region: US
    apiKeySecretKey: NEWRELIC_API_KEY
```

and a `NEWRELIC_API_KEY` block in `setup-secret.sh`, which puts the key into the `sariva-platform-extras` Secret the chart references — the key never lands in `values.yaml`. (On a VM the `.env` value may also be `file:///path` or `env://VAR` holding the key, like the other credential references.)

## Step 2 — Validate

```bash theme={null}
sariva validate logs
```

makes **one** tiny NRQL read (`SELECT count(*) FROM Log SINCE 5 minutes ago`) through the configured key and tells you which of these you are looking at:

| Outcome | What to fix |
| - | - |
| ✓ Logs — New Relic NerdGraph reachable at api.newrelic.com (account 1234567, US) — N log line(s) in the last 5 minutes | nothing — and if N is 0, logs are not arriving in this account |
| ✗ credentials rejected — New Relic rejected the User API key or it lacks query permission; check `NEWRELIC_API_KEY` | the key (type *User*, the right account, not revoked) or the user's access to the account |
| ✗ rate-limited (429 after retries) | New Relic throttled the account; try again, and lower the interval or budget if it recurs |
| ✗ unreachable — api.newrelic.com | egress / proxy, or the region (EU accounts need `NEWRELIC_REGION=EU`) |

After a successful read it checks **every registered app** the same way an SRE approval does (below): lines in the last 24 h at the app's `log_locator`, which of its `log_fields` those lines carry, and one sample line as Sariva would show it:

```
✓ Log fields: payments-consumer   Log-field check for `payments-consumer` passed — found `message` on 3 of 21 lines, `event` on 18 of 21 lines, `error` on 6 of 21 lines (last 24 h). Sample: error · DeserializationError: failed to process message · Expecting value: line 1 column 1 (char 0)
✗ Log fields: orders-api FAILED
    reason: `orders-api`'s recent lines (40 in 24 h) carry none of its log_fields (`msg`), so reads will say they couldn't read its errors. Fix: set log_fields on orders-api, e.g. ["message", "event", "error"].
⚠ Log fields: billing-worker  `billing-worker` has no log_fields set, so only `message` is searched (`message` on 3 of 21 lines, last 24 h). If it logs JSON, its errors are in other fields — set log_fields on billing-worker, e.g. ["message", "event", "error"]. …
```

A ✗ (no lines at the locator, or none of the listed fields on them) means scans of that app cannot see its errors; a ⚠ means `log_fields` is unset. On a VM the app registry lives inside the container, so add `--api-url https://<your Sariva host>` (with `SARIVA_PLATFORM_API_KEY` set): the running platform runs each app's check and lists its usage (`POST /api/v1/log-scanning/field-check`, `GET /api/v1/log-scanning`).

`sariva validate all` checks only that the variables are present; it never reads. `GET /api/v1/health` carries a `log_scanning` block with the source, the period's usage, and per app both approvals (`chat_scan`, `monitor`) with their states and caps.

## Step 3 — App teams register where their logs are

Each app's registration carries `log_locator`: the log attributes that select its lines in `FROM Log` — the same filter you would type into the Logs UI. Sariva builds the `WHERE` clause from them; nobody writes NRQL. `alert_on_error_pattern` entries are RE2 regular expressions (a plain word matches as a substring). Registering both posts **one** request for scheduled monitoring to the SRE channel; monitoring starts when an SRE replies **approve** (optionally *approve, every 15 min, cap 5000* — an interval of 1, 5 or 15 minutes and a cap in queries per day) in that post's thread. On-demand chat reads are a separate approval with a look-back and a daily limit, requested the first time someone asks about the app's logs. The app-team side is on [App logs & pod health](https://sariva.mintlify.site/app-teams/logs-and-pod-health.md).

## JSON logs — tell Sariva which fields to search

New Relic **parses a JSON log line into attributes**. A line your app writes as

```json theme={null}
{"app": "payments-consumer", "level": "error", "event": "DeserializationError: failed to process message", "error": "Expecting value: line 1 column 1 (char 0)", "topic": "payments.events", "partition": 0, "offset": 4102}
```

is stored with `level`, `event`, `error`, … and **no `message` attribute**. Plain-text lines — for example librdkafka's on stderr (`%5|…|REQTMOUT|rdkafka#consumer-1| … Timed out OffsetCommitRequest in flight`) — keep the whole line in `message` and have no `level`. One app often writes both.

So each app's registration names the attributes to search in `log_fields`:

```json theme={null}
"log_fields": ["message", "event", "error"]
```

* Every pattern matches if it appears in **any** listed field, so JSON lines and plain-text lines are read in the same query. Matching never relies on `level`; a line without `level` is still read.
* **Unset means `["message"]`** — right for plain-text logs, blind to JSON lines. Every SRE request post says which fields will be searched ("searches only `message` (no log\_fields set)" when unset).
* Plain attribute names only (letters, digits, `.`, `_`, `-`; up to 8). `timestamp` is not a log field.
* A sample line is shown as `level · <each field>`: `error · DeserializationError: failed to process message · Expecting value: line 1 column 1 (char 0)`.

**If the fields are wrong**, Sariva says so instead of "no errors": when the app has recent lines but none of them carry any listed field, a chat answer says it *couldn't read this app's errors — the listed log fields aren't on its recent lines* and how to fix it, and scheduled monitoring treats the app as not configured (never as clean). When only some lines carry the fields, the reply says how many were searched.

**Checked when it matters.** Right after an SRE approves on-demand scans or monitoring for an app, Sariva checks its fields once. A problem — no lines at the locator, none of the fields found, or no `log_fields` on New Relic — is posted to the app's thread and in the SRE's approval thread, with the fix (e.g. `set log_fields on payments-consumer, e.g. ["message", "event", "error"]`); the approval still stands. A pass is one line naming the fields found. Changing `log_fields` with `PUT /api/v1/apps/{alias}` on an approved app runs the same check. To see an app's attributes yourself: `FROM Log SELECT * WHERE container_name = 'payments-consumer' SINCE 30 minutes ago LIMIT 5`.

CloudWatch Logs needs none of this: `@message` holds the whole raw line, JSON or not, and `log_fields` is ignored there.

## What it costs

Sariva does not know an app's log volume before it reads it, so each request states the basis honestly: at the default 5-minute interval an app costs **288 NRQL queries a day** (one query per interval, all patterns in it); the suggested cap is four times the estimate, rounded up, and the SRE may set any other. At 80% of its cap the app's chat thread is warned; at 100% that app's monitoring pauses until the next day and resumes by itself. On-demand reads count toward the app's daily limit (50 by default, SRE-set). The optional `LOG_SCAN_BUDGET` caps the whole install on top.

## Switching an existing install to New Relic

Set `LOG_SOURCE=newrelic` plus the three `NEWRELIC_*` variables in `.env` (VM) or the `logSource` block in `values.yaml` and the Secret key (Kubernetes), restart, and run `sariva validate logs`. Every app's `log_locator` must then name New Relic attributes — a CloudWatch `log_group` locator reads as *no log location* on New Relic and the app's scanning stays unverified until its team updates it with `PUT /api/v1/apps/{alias}`. Approvals carry over.


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