Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(capture): document the AI endpoint ingestion warnings (#76155)

Eli Reismanf4fe2b304297
diff --git a/.agents/skills/adding-ingestion-warnings/SKILL.md b/.agents/skills/adding-ingestion-warnings/SKILL.md
index 1f5708283a9b..af21dbff558e 100644
--- a/.agents/skills/adding-ingestion-warnings/SKILL.md
+++ b/.agents/skills/adding-ingestion-warnings/SKILL.md
@@ -22,7 +22,7 @@ An unregistered type is a compile error (`IngestionWarningType` is the registry'
To add a new warning:
1. **Register the type** in `INGESTION_WARNING_TYPES`, inside the matching group comment block. Pick:
- - `category` — one of `size`, `merge`, `event`, `transformation`, `replay`. Extend `IngestionWarningCategory` only when the warning genuinely doesn't fit an existing group; new categories flow into API filters and agent-facing docs, so keep the vocabulary small.
+ - `category` — one of `size`, `merge`, `event`, `quota`, `transformation`, `replay`. Extend `IngestionWarningCategory` only when the warning genuinely doesn't fit an existing group; new categories flow into API filters and agent-facing docs, so keep the vocabulary small.
- `severity` — follow the convention: `error` = the event or message was dropped, `warning` = ingested but modified or partially rejected, `info` = informational or an intentional, team-configured drop.
2. **Emit it** (see below), passing only per-occurrence fields: `details`, `pipelineStep`, optional `key` / `alwaysSend`.
3. **Update downstream surfaces** (see checklist).
@@ -70,7 +70,7 @@ INGESTION_WARNING_TYPES (all entries) # nodejs — source
**Every edit to `INGESTION_WARNING_TYPES` requires regenerating and committing the artifact** — not just capture-produced types. The nodejs no-drift test (`generate-ingestion-warning-types.test.ts`) fails CI whenever the committed artifact and the generator output diverge, including when a type you didn't add lands on master while your branch is in flight: rebase, regenerate, recommit.
-The artifact is committed _inside_ the Rust crate so the isolated Rust Docker/CI build context stays self-contained — no cross-workspace file reads. `captureProduced: true` marks the types capture may set via the structured envelope property: it derives the `CAPTURE_PRODUCED_WARNING_TYPES` trust allowlist the consumer enforces, and the Rust `from_tag_domain_equals_the_capture_trust_allowlist` test welds capture's hand-written `from_tag` allowlist to exactly that set — skew in either direction (flag without an arm, arm without the flag) silently drops warnings in production, so the test makes it a red CI run instead.
+The artifact is committed _inside_ the Rust crate so the isolated Rust Docker/CI build context stays self-contained — no cross-workspace file reads. `captureProduced: true` marks the types capture may set via the structured envelope property: it derives the `CAPTURE_PRODUCED_WARNING_TYPES` trust allowlist the consumer enforces, and the Rust `capture_emit_routes_equal_the_capture_trust_allowlist` test welds capture's two emit routes — the hand-written `from_tag` allowlist and the `DIRECT_EMIT` list — to exactly that set, and also enforces that no type is on both — skew in either direction (flag without an arm, arm without the flag) silently drops warnings in production, so the test makes it a red CI run instead.
To add a **capture-produced** type:
@@ -86,16 +86,16 @@ Services that know `team_id` (the personhog services) skip the envelope and prod
Warning::new(WarningType::MyNewType)
.with_detail("personId", uuid)
.with_detail("message", msg)
- .into_row(team_id, "my-service")
+ .into_row(team_id, MY_SERVICE_WARNINGS)
```
-`into_row` injects `teamId` and the registry's `category`/`severity` over the caller's details (they cannot be spoofed or forgotten), and stamps the ClickHouse-format timestamp. A direct-row type needs **no** `captureProduced` flag and no `from_tag` arm — register it, regenerate the artifact, and emit. See the module doc in `rust/common/ingestion_warnings/src/serializer.rs` for the envelope-vs-row correspondence table and the trust rationale (the envelope lane is attacker-writable, so the consumer stamps classification; the row topic is ACL-guarded, so the producer does).
+`into_row` takes a `WarningSource` (declare one const per emit site, as capture does in `src/lib.rs`) and injects `teamId` and the registry's `category`/`severity` over the caller's details (they cannot be spoofed or forgotten), and stamps the ClickHouse-format timestamp. A direct-row type needs **no** `captureProduced` flag and no `from_tag` arm — register it, regenerate the artifact, and emit. See the module doc in `rust/common/ingestion_warnings/src/serializer.rs` for the envelope-vs-row correspondence table and the trust rationale (the envelope lane is attacker-writable, so the consumer stamps classification; the row topic is ACL-guarded, so the producer does).
Emitting from Rust:
- **Emit it** via `WarningEmitter::emit(token, source, warning, details, count)` — the builder injects `count` and `pipelineStep` into details and stamps `type`/`source`/`details` into the event properties the consumer reads. Use the same camelCase details keys as nodejs (`distinctId`, `eventUuid`, ...). The envelope's top-level `distinct_id` is always the token (never the offending id), so an oversized offending distinct_id can't make the consumer drop the warning.
- **`source` identifies the producer** (`src/lib.rs`): a `WarningSource { service, path, pipeline_step }`. `service` is the stable message `source` field and metric label (e.g. `"capture"`) — pick one per service, don't invent a new value per call site. `path` is metric-only, for splitting volume within one service's emit sites (e.g. `"v1_analytics"`); it never reaches the message. `pipeline_step` is stamped into the envelope's details as `pipelineStep`. Capture declares one source per emit site: `CAPTURE_V1_ANALYTICS` and `CAPTURE_V1_RATE_LIMIT` (path `v1_analytics`), and `CAPTURE_LEGACY_ANALYTICS` and `CAPTURE_LEGACY_RATE_LIMIT` (path `legacy_analytics`) — see the constants in `src/lib.rs` for the current list.
-- **Best-effort, fire-and-forget**: throttled per `(token, type)` per pod, never awaited, never fails the caller. Capture gates it behind `CAPTURE_INGESTION_WARNINGS_ENABLED` (default off; see `rust/capture/src/config.rs`). The producer is a `common-kafka` `ThreadedProducer` (built via `create_threaded_kafka_producer` with `observe_delivery` as its delivery callback, so delivered/failed outcomes are counted on the producer's own poll thread — no per-message task). It reuses the main event cluster's hosts/TLS and the `client_ingestion_warning` topic but runs on its own dedicated `KafkaConfig`: the fire-and-forget policy (`client.id=capture-ingestion-warnings`, `acks=1`, `retries=0`, `linger.ms=100`, a bounded 10k-message queue, a 5s message timeout) is fixed in code as the `WARNINGS_KAFKA_*` constants in `rust/capture/src/setup.rs` — not env-configurable — while only the two capacity/safety limits stay tunable via env (`CAPTURE_INGESTION_WARNINGS_KAFKA_QUEUE_MIB` and `..._MESSAGE_MAX_BYTES`). So a slow or saturated warnings topic can never contend with the main event producer.
+- **Best-effort, fire-and-forget**: throttled per `(token, type)` per pod, never awaited, never fails the caller. Capture gates it behind `CAPTURE_INGESTION_WARNINGS_ENABLED` (default off; see `rust/capture/src/config.rs`). The producer is a `common-kafka` `ThreadedProducer` (built via `create_threaded_kafka_producer_no_ping` with `observe_delivery` as its delivery callback, so delivered/failed outcomes are counted on the producer's own poll thread — no per-message task). It runs on its own dedicated `KafkaConfig` and its own destination: the emitter reads only `CAPTURE_INGESTION_WARNINGS_KAFKA_{HOSTS,TOPIC,TLS}` and never falls back to the main event cluster's `KAFKA_*` settings, so a deployment whose sink and warnings destination are different clusters (capture-ai produces events to WarpStream but warnings to MSK) is configurable. Empty hosts or topic means the emitter reports itself disabled rather than guessing. the fire-and-forget policy (`client.id=capture-ingestion-warnings`, `acks=1`, `retries=0`, `linger.ms=100`, a bounded 10k-message queue, a 5s message timeout) is fixed in code as the `WARNINGS_KAFKA_*` constants in `rust/capture/src/setup.rs` — not env-configurable — while only the two capacity/safety limits stay tunable via env (`CAPTURE_INGESTION_WARNINGS_KAFKA_QUEUE_MIB` and `..._MESSAGE_MAX_BYTES`). So a slow or saturated warnings topic can never contend with the main event producer.
- **Crate deps**: `common-ingestion-warnings` depends on `common-types` (for `CapturedEvent`) and `common-kafka` (the producer) — not on `capture` or any service crate. `WarningEmitter` is a plain trait object (`Arc<dyn WarningEmitter>`), so any Rust service can depend on the crate and wire it the way capture does in `router::State` / `setup.rs`; a team-aware service just supplies its own token.
## Rolling out a new capture-produced type
diff --git a/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx b/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
index 3dd3fe0a1add..3048b2ca2be5 100644
--- a/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
+++ b/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
@@ -55,6 +55,10 @@ export const WARNING_TYPE_TO_DESCRIPTION: Record<string, string> = {
invalid_event_uuid: 'Rejected a batch containing an event with an invalid UUID',
duplicate_event_uuid: 'Rejected a batch containing duplicate event UUIDs',
high_volume_distinct_id: 'Skipped person profile processing for a high-volume distinct ID',
+ // Emitted by the capture service for its AI endpoints
+ invalid_ai_event: 'Discarded an AI event with an unsupported event name or no $ai_model',
+ invalid_ai_payload: 'Rejected a malformed AI or OpenTelemetry request',
+ no_ai_spans_ingested: 'Accepted an OpenTelemetry export with no AI spans, so nothing was ingested',
}
// Explicit anchor on https://posthog.com/docs/data/ingestion-warnings for each warning type.
diff --git a/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md b/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
index b669081fac96..65f9eda1dc5a 100644
--- a/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
+++ b/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
@@ -70,6 +70,16 @@ Those decisions come only from this skill's guidance and your own reasoning.
| `event_dropped_too_old` | Intentional: the event is older than the team's configured drop threshold | Read [references/fixing-event-dropped-too-old.md](references/fixing-event-dropped-too-old.md) — mind mobile SDKs: offline queues legitimately deliver days-old events; threshold changes are the user's call |
| `cookieless_missing_timestamp` / `cookieless_timestamp_out_of_range` / `cookieless_missing_user_agent` / `cookieless_missing_ip` / `cookieless_missing_host` | Cookieless-mode event dropped: a field required to compute the cookieless ID was missing or invalid | Read [references/fixing-cookieless-warnings.md](references/fixing-cookieless-warnings.md) — the missing field identifies the broken layer; beware the silent variant where a server relay omits $ip and users collapse onto the server's IP |
+### LLM analytics endpoints (`event`)
+
+Emitted by capture for its two dedicated AI endpoints, `/i/v0/ai` (a single event per request, sent multipart) and `/i/v0/ai/otel` (OTLP traces). These reject at the edge, so the events never reach the pipeline and appear nowhere else. Read the `path` detail to tell the endpoints apart: `ai_events` or `ai_otel`.
+
+| Type | What happened | Fix |
+| ---------------------- | ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `invalid_ai_event` | Event rejected: the name isn't one of the six `$ai_*` types, or `$ai_model` is missing or not a string | Read [references/fixing-ai-endpoint-rejections.md](references/fixing-ai-endpoint-rejections.md) — usually ordinary analytics pointed at the AI endpoint |
+| `invalid_ai_payload` | Request rejected: malformed multipart or OTLP body, or too many spans in one export | Read [references/fixing-ai-endpoint-rejections.md](references/fixing-ai-endpoint-rejections.md) — `format`, `stage`, and `part` details name which check failed |
+| `no_ai_spans_ingested` | OTLP export accepted with a 200 but contained no AI spans, so nothing was ingested | Read [references/fixing-ai-endpoint-rejections.md](references/fixing-ai-endpoint-rejections.md) — instrumentation is emitting spans no AI provider convention matches |
+
### Heatmaps (`event`)
| Type | What happened | Fix |
diff --git a/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-ai-endpoint-rejections.md b/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-ai-endpoint-rejections.md
new file mode 100644
index 000000000000..71625b1f0bec
--- /dev/null
+++ b/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-ai-endpoint-rejections.md
@@ -0,0 +1,59 @@
+# Fixing AI endpoint rejections
+
+Covers `invalid_ai_event`, `invalid_ai_payload`, and `no_ai_spans_ingested`.
+
+These come from capture's two dedicated LLM analytics endpoints, not from the ingestion pipeline:
+
+- `/i/v0/ai` — one event per request, sent as multipart so large prompt and completion bodies can ride along as separate parts. Warnings carry `path: ai_events`.
+- `/i/v0/ai/otel` — OTLP trace export, protobuf or JSON. Warnings carry `path: ai_otel`.
+
+Both reject at the edge, so a rejected event reaches nothing downstream. It is not in `events`, not in any insight, and has no other trace beyond the warning. `count` is the number of events or spans that didn't land.
+
+Check `lib` and `libVersion` first on every one of these. A rejection concentrated on one SDK version is an upgrade, not a payload problem.
+
+## `invalid_ai_event`
+
+The event reached the endpoint and parsed, but isn't a valid AI event.
+
+Two causes, told apart by the details:
+
+**An unsupported event name** (`eventName` is present). The endpoint accepts only `$ai_generation`, `$ai_trace`, `$ai_span`, `$ai_embedding`, `$ai_metric`, and `$ai_feedback`. Anything else is rejected.
+
+If `eventName` is something like `$pageview` or a custom event, ordinary analytics is being pointed at the AI endpoint. That is usually a misconfigured host or proxy rule rather than deliberate. Send those to `/i/v0/e` or `/batch` instead. If it looks like an AI event with the wrong name (`ai_generation` without the `$`, or `$ai_completion`), fix the name at the callsite.
+
+**No usable `$ai_model`** (no `eventName` in the details). Every AI event must carry `$ai_model` as a non-empty string. A model set to `null`, a number, or an empty string is rejected the same as a missing one. This usually means the value is unset at the callsite: the variable holding the model name is empty when the provider call fails early, or the SDK wrapper wasn't given a model.
+
+## `invalid_ai_payload`
+
+The request body couldn't be used. Read the details to see which check failed.
+
+**`format`** is present for OTLP decode failures, and names what the content-type resolved to:
+
+- `format: unknown` — the content-type itself is wrong. OTLP requires `application/x-protobuf` or `application/json`. An exporter sending `application/octet-stream` or no content-type lands here.
+- `format: protobuf` or `json` — the content-type was right but the body didn't match it. Check for a proxy that rewrites or re-compresses request bodies, and for a `content-encoding` other than gzip, which is the only one supported.
+
+**`stage`** and `spanCount` are present when an export carried too many spans. `stage: raw` means more than 1000 spans arrived before filtering; `stage: ai` means more than 100 AI spans survived filtering. Both mean the exporter needs a smaller batch size or a shorter flush interval. `limit` is the cap that was exceeded.
+
+**`part`** is present for multipart problems on `/i/v0/ai`, naming the offending part. Common cases: a field that isn't `event`, `event.properties`, or `event.properties.<name>`; a blob part with no `Content-Type` or an unsupported one (only `application/octet-stream`, `application/json`, and `text/plain` are accepted, reported in `contentType`); an empty blob; or a blob property name containing dots, which isn't allowed since only top-level properties can be sent as blobs.
+
+**Neither** means the multipart framing itself was wrong, or the event part wasn't valid UTF-8 JSON.
+
+Note the deliberate omission: the underlying parser error is not in the details. It can contain arbitrary payload bytes, so it stays in capture's logs.
+
+## `no_ai_spans_ingested`
+
+This one is different: the request succeeded. The exporter got a `200` and no error, and nothing was ingested.
+
+It fires when an OTLP export carried spans but none of them were AI spans. `rawSpanCount` is how many arrived.
+
+Capture keeps a span only if its attributes match a known AI provider convention: `gen_ai.*`, `ai.*`, `eve.*`, `traceloop.*`, `pydantic_ai.*`, or `llm.request.type`. Everything else is dropped as ordinary tracing, which is correct behavior for a mixed batch. This warning means _every_ span in the request was dropped that way.
+
+Almost always one of:
+
+- **OTLP traces are being exported to PostHog wholesale.** A generic tracing setup was pointed at `/i/v0/ai/otel` without filtering, so HTTP and database spans arrive with no AI spans among them. Restrict the exporter to the AI instrumentation, or accept that non-AI batches produce nothing.
+- **The LLM instrumentation isn't loaded.** The exporter works, but the library that adds `gen_ai.*` attributes isn't installed or initialized, so the LLM calls emit plain spans. Confirm the AI instrumentation package is registered before the provider client is constructed.
+- **A custom or unsupported convention.** Hand-rolled spans using in-house attribute names won't match. Rename them to the `gen_ai.*` semantic conventions.
+
+To see what is actually arriving, pull the spans' attribute keys from your own tracing backend rather than from PostHog. Nothing reached PostHog to inspect.
+
+A mixed batch that contains at least one AI span does **not** warn, so a team seeing this occasionally alongside successful ingestion is sending some batches with no AI activity in them. That is usually benign. Sustained firing with no AI events landing is the case worth acting on.