# Ingest rules

Drop, redact or parse telemetry as it arrives, before Maple stores or bills it: rule types, conditions, redaction, parse steps, ordering, impact numbers, the dry run and suggested rules.

Ingest rules run on your telemetry as it arrives at Maple's ingest gateway, before it is stored or counted toward your bill. Use them to drop data you do not need, redact personal data and secrets, or turn log lines into attributes.

Find them under **Settings → Ingestion → Ingest rules**. A rule applies to new data within 30 seconds of saving. Data already stored is unchanged.

Rules cover OTLP traces, logs and metrics, including data from the Cloudflare, GCP and AWS connectors. Session events, product events and session replays are not covered.

## Rule types

| Action     | What it does                                                                           | Signals                |
| ---------- | -------------------------------------------------------------------------------------- | ---------------------- |
| **Drop**   | Removes matching records, or keeps a sample of them.                                    | Traces, logs, metrics  |
| **Redact** | Replaces sensitive values in place: whole attribute values, detected values or regex matches. | Traces, logs, metrics  |
| **Parse**  | Turns a log body or attribute into attributes, and can set the log's severity and timestamp. | Logs only            |

The empty rule list offers templates to start from: **Redact emails and card numbers**, **Drop debug logs**, **Drop health-check spans**, **Hash user identifiers** and **Parse JSON logs**.

## Create a rule

The editor reads as a sentence:

1. **When**: pick the signals the rule applies to.
2. **Where**: add conditions. With none, every record matches. A drop rule needs at least one.
3. **Then**: pick **Drop**, **Redact** or **Parse** and fill in the details.
4. Give the rule a name and click **Create rule**.

While you edit, the page shows a [dry run](#dry-run) over the last 24 hours and a [live preview](#live-preview) over recent records.

Only people with the **Manage ingest rules** permission can create, change or delete rules. Engineers and admins have it. See [Roles](/docs/reference/roles).

## Conditions

A rule looks at one record at a time: a span, a log record or a metric data point. It applies when the record's signal is one the rule picked and **every** condition matches.

| Field                  | Reads                                         | Signals         | Operators                                                                   |
| ---------------------- | --------------------------------------------- | --------------- | --------------------------------------------------------------------------- |
| **service**            | The resource's `service.name`                 | All             | is, is not, is one of, is none of, starts with, contains, matches regex     |
| **name**               | Span name or metric name                      | Traces, metrics | Same as service                                                             |
| **attribute**          | A span, log or data point attribute, by key   | All             | Same as service, plus exists and does not exist                             |
| **resource attribute** | A resource attribute, by key                  | All             | Same as attribute                                                           |
| **body**               | The log body as text                          | Logs            | is, is not, starts with, contains, matches regex                            |
| **severity**           | The log severity                              | Logs            | is below, is at least (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)  |
| **span kind**          | `unspecified`, `internal`, `server`, `client`, `producer`, `consumer` | Traces | is one of, is none of                          |
| **span status**        | `unset`, `ok`, `error`                        | Traces          | is one of, is none of                                                       |

- Values are compared as text. Numbers and booleans are compared in their text form. Arrays, maps and byte values never match a comparison. They only satisfy **exists**.
- A missing attribute fails every operator except **is not**, **is none of** and **does not exist**, which pass.
- **matches regex** matches anywhere in the first 16 KiB of the value. Lookarounds, backreferences and a few other constructs are refused when you save. Only a leading `(?i)` flag is accepted, for case-insensitive matching.
- Severity uses the log's severity number. When that is unset, it is read from the severity text (`info`, `WARN`, `error` and so on). A log whose severity is still unknown matches no severity condition.

## Drop rules

A drop rule removes the records its conditions match.

**Keep a sample** keeps a share of the matches, from 0 to 100 percent. 0 drops every match. Sampling follows the trace id, so every span and log of a trace that the rule matches gets the same answer. A kept trace stays whole only when the rule matches all of its records: a rule that matches some spans by name drops just those. A record without a trace id is kept at random.

- Metrics can only be dropped entirely. A drop rule that includes metrics must keep 0%.
- When several drop rules match one record, it survives only if every one of them keeps it.
- Dropped spans are missing from service metrics and the service map.
- Spans a drop rule keeps by sampling carry no sample weight, so throughput for that traffic is underestimated. See [Sampling and throughput](/docs/concepts/sampling-throughput#limitations).

## Redact rules

A redact rule replaces values. Pick what to redact, where to look, and how to replace it.

**What to redact** (at least one of):

- **Keys**: attribute keys whose whole value is replaced, comma-separated. `*` matches any characters and matching is case-insensitive: `*password*`, `http.request.header.*`.
- **Detect**: built-in detectors that replace only the matched text: **Email addresses**, **Card numbers** (checked with Luhn), **JWTs**, **API tokens** (common provider key formats and bearer tokens), **IPv4 addresses**, **IPv6 addresses**, **Phone numbers** and **IBANs** (checked with mod-97).
- **Custom patterns**: one regex per line, for example `ORD-[0-9]+`. Only the matched text is replaced.

**Look in** (at least one):

| Place                   | Covers                                                                                      |
| ----------------------- | ------------------------------------------------------------------------------------------- |
| **Attributes**          | The record's attributes, the span status message, and for metrics the exemplars' attributes. |
| **Resource attributes** | The resource's attributes.                                                                  |
| **Span events**         | Span event attributes, such as `exception.message`. Traces only.                            |
| **Log body**            | The log body. Logs only.                                                                    |

Arrays and maps are searched all the way down. Detectors and patterns scan at most the first 16 KiB of each value.

**Replace with**:

| Method     | A key match                                         | A detector or pattern match                         |
| ---------- | --------------------------------------------------- | --------------------------------------------------- |
| **Mask**   | The value becomes `[REDACTED]`.                     | The text becomes `[REDACTED:email]` (or the detector's name), or `[REDACTED]` for a pattern. |
| **Hash**   | A text value becomes `hash:<hex16>`. Other types are masked. | The text becomes `hash:<hex16>`.             |
| **Remove** | The attribute is removed.                           | Same as **Mask**.                                   |

A hash is a keyed hash with a salt unique to your organization, so the same value always gives the same hash and you can still group and count by it. Hashing is pseudonymization: values with few possibilities, such as phone numbers, can be guessed.

Some keys are never redacted, because Maple uses them to route, attribute and bill data: `service.name`, `org_id`, and Maple's own `maple_*` stamps (such as `maple_org_id`). A rule that names one is refused.

## Parse rules

A parse rule applies to logs only. Its conditions pick the logs, and its **Steps** (1 to 10) run in order on each one. Every step reads one source: the **Body**, or an **Attribute** by key.

| Step          | Reads                                       | Writes                                                                                                 |
| ------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **JSON**      | Text holding a JSON object, or a structured body | One attribute per value, with dotted keys (`http.status`). Arrays are kept whole.                  |
| **Regex**     | Text                                        | One attribute per named group, for example `(?<status>[0-9]+)`.                                         |
| **Grok**      | Text                                        | One attribute per `%{PATTERN:field}`, from a built-in pattern library.                                 |
| **Severity**  | A level name (`warn`, `ERROR`, `notice`) or a number from 1 to 24 | The log's severity.                                              |
| **Timestamp** | Text or a number                            | The log's timestamp.                                                                                   |

- **JSON**, **Regex** and **Grok** take an optional prefix, added to every key they write. `http.` gives dotted keys such as `http.status`.
- The grok library has the usual building blocks (`INT`, `NUMBER`, `WORD`, `IP`, `GREEDYDATA`, `TIMESTAMP_ISO8601`, `LOGLEVEL` and more) and `COMMONAPACHELOG` and `COMBINEDAPACHELOG`, which write OpenTelemetry keys such as `client.address` and `http.response.status_code`. `%{NUMBER:bytes:int}` and `:float` convert the capture.
- **Timestamp** formats: **RFC 3339 / ISO 8601**, **Unix seconds**, **Unix milliseconds**, **Unix microseconds**, **Unix nanoseconds** and **Common log** (`10/Oct/2000:13:55:36 -0700`).
- A written key replaces an existing attribute with the same key. Protected keys (`service.name`, `org_id`, `maple_*`) are never written.

When a step fails (no match, invalid JSON, a timestamp out of range), the log is kept and gets a `maple.parse.error` attribute such as `regex: no match`. Later steps still run, and the rule keeps its first failure. A redact rule on attributes can remove or mask `maple.parse.error` like any other key.

Parsing never changes what you are billed: a log is metered on the size it was sent, whatever attributes parsing adds.

## Order of evaluation

1. **Drop rules run first**, against each record as it arrived.
2. **Redact rules run next**, in list order, on the records that survived. Each one sees the output of the one before. Their conditions are also checked against the record as it arrived.
3. **Parse rules run last**, in list order, on the redacted logs. A parse step only ever reads redacted text, so a secret masked in the body is masked in everything parsed from it. Each parse rule's conditions see the body and attributes as redaction and earlier parse rules left them, but resource attributes as they arrived (resource redaction is applied afterwards).
4. Redact rules that cover **Attributes** or **Log body** then run once more over the attributes parsing wrote, so key and detector rules reach them too.

Drop and redact conditions never see a value parsing produces. To redact a parsed value, rely on step 4 instead of a condition.

Change the order with **Move up** and **Move down** in a rule's menu. Order matters for redact and parse rules. Turn a rule off with its switch to stop it without deleting it.

## Impact

The gateway counts what each rule did. The counts lag by up to a minute.

In the rule list, the **Last 24h** column shows each rule's effect over the last 24 whole UTC hours, with an hourly sparkline:

- A drop rule shows records dropped, such as `1.2M dropped`, or `1.2M of 1.4M dropped` when it matched more than it dropped. Below it is the size of the dropped records.
- A redact rule shows values redacted and the number of records it matched.
- A parse rule shows logs parsed.
- **No hits** means it matched nothing in that window.

A saved rule's page has an **Impact** card with the same counts over **24h** or **7d**: a main figure (**Dropped**, **Redacted** or **Parsed**), **Bytes dropped**, the peak hour (or peak 6 hours over 7 days), a chart, and a row per signal under **By signal**.

What the numbers mean:

- **Matched** is the records the rule's conditions matched.
- **Dropped** is the records the rule removed. Matched minus dropped is not the same as kept: when several drop rules match one record, the record is credited to the first one that drops it, so a later rule shows it as matched but not dropped.
- **Bytes dropped** is the encoded size of the dropped records. Your bill is reduced by the dropped share of each request's original size, which can differ slightly, for example for data that a connector converts before it reaches the rules.
- **Values redacted** counts each value replaced, so one record can count several times.

## Dry run

The editor's **Last 24 hours, stored** card estimates what a draft rule would do to the logs and spans you stored in the last 24 hours. It updates a moment after you stop editing.

- A drop rule shows **Would drop** with a share of the stored records, and about how many bytes it would keep off the bill.
- A redact or parse rule shows how many records it **Matches**.
- The services with the most matches are listed below.
- On busy organizations the scan covers the most recent hours it can read and applies those rates to the whole day. The card then says, for example, "Rates from the last 6 hours, applied to the day".

It is an estimate. Data your other rules already dropped was never stored, and attribute values are compared as they were stored. Only logs and traces are counted, not metrics.

## Live preview

The **Preview** card runs the draft against the most recent records from the last hour (pick **Logs** or **Traces**, and a service or **All services**). It shows which records would be dropped, each value before and after redaction, or which logs a parse rule would parse and which would fail.

- Stored samples keep attributes as text and bodies flattened, so types and structured bodies can differ from what the gateway sees.
- The sample has no span events, so redactions there only show in stored data.
- A hashed value in the preview differs from the one that will be stored.

## Suggested rules

Under the rule list, **Suggested from the last 24 hours** proposes drop rules from your own data:

- Debug and trace logs of a service: drop.
- Health-check spans (span names with `health`, `healthz`, `readyz`, `livez`, `readiness`, `liveness`, `ping` or `heartbeat` as a word): drop.
- A service's logs below warn, when its info logs are at least a tenth of all log bytes: keep 10%.

Each suggestion shows how much it would save a day and how many records it covers. A suggestion must cover at least 1,000 records and save at least 0.5% of all stored log and span bytes. The six that save the most are listed. Click **Drop** or **Sample 10%** to open the editor with the rule filled in, then review and save it.

A suggestion disappears once an enabled drop rule has exactly its conditions and keeps no more than it would. Log suggestions need access to logs and span suggestions need access to traces.

## Billing

Bytes a drop rule removes are never metered, so dropped data is not billed. **Settings → Billing & usage** shows, per signal, how much rules dropped in the current billing cycle ("dropped by rules, not billed").

Redaction and parsing do not change the bill: data is metered on the size it was sent, less what drop rules removed.

## Limits and errors

| Limit                                  | Value                             |
| -------------------------------------- | --------------------------------- |
| Rules per organization                 | 50                                |
| Conditions per rule                    | 20                                |
| Values per condition                   | 100, up to 1,024 characters each  |
| Redacted keys per rule                 | 32                                |
| Custom patterns per rule               | 10, up to 512 characters each     |
| Steps per parse rule                   | 10                                |
| Parse pattern                          | 1,024 characters                  |
| Parse prefix                           | 64 characters                     |
| Rule name                              | 120 characters                    |
| Bytes of one value a rule scans        | 16 KiB                            |

All of an organization's regexes together (conditions, redact patterns and parse patterns, in enabled and disabled rules) must fit a compiled-size budget. The editor refuses a rule that would go past it. See [Limits](/docs/reference/limits#ingest-rules) for every limit.

The ingest gateway can refuse a request because of rules:

| Status | Code                       | When                                                                                                    | Retry                     |
| ------ | -------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------- |
| `503`  | `ingest_rules_unavailable` | Your rules could not be loaded and none were loaded before, so Maple refuses the data rather than store it unredacted. Also returned when your rules' regexes together are too large to compile. | Yes, after 5 s (simplify the regexes in the second case) |
| `413`  | `ingest_rules_scan_budget` | One request needs more rule scanning than it may use.                                                   | No. Send smaller batches  |

If a reload of your rules fails after they loaded once, the gateway keeps applying the rules it has. OpenTelemetry SDKs and the Collector retry `503` on their own. See [Ingest API status codes](/docs/reference/ingest#status-codes).

## Manage rules from an assistant or the API

The [MCP server](/docs/reference/mcp#ingest-rules) has `list_ingest_rules`, `preview_ingest_rule` (a dry run of a saved or draft rule over recent traces or logs) and `manage_ingest_rule` (create, change or delete). Rules are also available through the `/v2/ingest_rules` [API](/docs/reference/api).
