Skip to main content

Analytics and the ingester

The ingester receives the events Otoroshi exports — GatewayEvent, the CloudApimSecurityEvent of the Threat Protection Suite, and the LLMUsageAudit and McpAudit audits of the LLM extension — and stores them twice, for two purposes. Install the exporter as described in Install.

/ingest​

POST /ingest
Authorization: Bearer <APIM_INGEST_TOKEN>

[ { "@type": "GatewayEvent", … }, … ]

The token is also accepted as an X-Apim-Ingest-Token header or a token query parameter. The body is a JSON array, a single event, { "events": [ … ] }, or newline-delimited JSON.

The computed path — mandatory, exhaustive​

Every GatewayEvent becomes one row, attributed to the catalogue at ingestion: workspace, API, plan, subscription, application, client id, method, path, status, duration, gateway overhead, backend duration, bytes in and out, error flag, caller IP and user agent.

A GatewayEvent names the api, the plan and the subscription of the key that called — its identity.apiRef, as the key said it at the time of the call — and the ingester attributes the call from it: the api, the plan, and the subscription with its application. A call made with the key an application shares between its APIs comes through the alias of its subscription: it is attributed to that subscription, under the client id the consumer called with, the shared credential's (apiRef.credential). A consumer a keyless plan identified has a plan and no subscription. An event without apiRef (an AI audit) is attributed from the client id of a credential the product holds.

A call is one event, served or refused, whatever the number of plans of its API: a plan that does not identify the caller lets the next one try and sends nothing of its own; a call no plan identifies is the event of its refusal.

A quota consumed, an attribution, a token count are counted, never sampled.

AI audits​

The LLM extension audits every call of an LLM provider (LLMUsageAudit) and of an MCP server (McpAudit, when the MCP endpoint has emit_audit_events): they are generic Otoroshi audit events (@type: AuditEvent, the kind in audit). They go to an AI usage table, attributed like the calls — the API, the subscription and the application of the key that called (its apiRef) —, with the provider, the model, the tool an MCP call called, the tokens (prompt and generation), the cost (the extension counts it in dollars, kept in micro-dollars). Their usage is kept, never their content: neither the prompt nor the answer, neither the arguments nor the result of a tool, and the key is named, not copied (it would carry its secret); the address of the caller and the end user are pseudonymised like the calls'. Collected from day one, even though AI and MCP products are not in this version — a feature can come later, uncollected data is lost.

The raw path — optional, sampled​

When enabled (APIM_INGEST_STORE_RAW, or Gateway → Ingestion), events are also kept as they came, for diagnosis and export — sampled, lightened and masked:

  • a share of the requests (100 % by default), decided by request, so that the events of one request are kept together; every error (status ≥ 400) is kept whatever the share, unless told otherwise. Only the raw path is sampled: the computed one counts everything;
  • the heavy embedded configurations are dropped (route, descriptor, JWT verifier): only the route's id, name and metadata remain; the headers can be left out too;
  • secrets in the URL are masked. Otoroshi already masks credential headers and secret fields of configurations; nothing masks a secret passed in a query parameter, so the ingester does it:
http://books.oto.tools:8080/v1/books?page=1&api_key=leaked-secret
http://books.oto.tools:8080/v1/books?page=1&api_key=********

Parameters whose names look like a secret (*token*, *secret*, *password*, api_key, key, sig, signature, code, auth*…) are masked.

Personal data — pseudonymised before they are stored​

An event names people: the address of the caller, the user signed in on the gateway, its browser, sometimes a path (/users/jane@example.com/orders/42). Gateway → Ingestion › Personal data says what becomes of them, before anything is stored, in both paths:

by defaultotherwise
Address of the caller — from, and the headers that carry it (X-Forwarded-For, X-Real-IP, Forwarded…)truncated to its network (/24, /48)kept, replaced by a pseudonym, or left out
Signed-in user — its email and name (a private app)replaced by a pseudonymkept, or left out
User agentkeptleft out
Pathskepttemplated: /users/{email}/orders/{n}, the values of the query left out

By default the product keeps the least that still serves: a network is enough to see where the traffic comes from, a pseudonym enough to count the calls of a user.

A pseudonym is a keyed hash (HMAC-SHA-256): one caller, one token — calls can still be counted by caller — never the address back without the key. The product makes the key, keeps it, and never shows nor exports it; rotating it breaks the link between the pseudonyms before and after. The client id of an application is not personal data: it stays, it is what attributes a call. The geolocation and the parsed user agent go with the address and the agent.

A change applies to what is received from then on. Every change of the policy is in the audit trail, with its values before and after.

Otoroshi exports the events whole — other uses need them — and leaves masking, pseudonymising and sampling to whoever stores them: what reaches the ingester has the personal data in clear, over the exporter's connection.

Security events​

The Threat Protection Suite sends one normalised event per decision, CloudApimSecurityEvent (category, action, outcome, severity, score, the caller, the route and its api, an incident). The ingester keeps it in a table of its own, attributed like the calls: the API from the event, and the plan, the subscription and the application from the key that called. A keyless caller, or one refused before it was identified, has the API only: the event does not carry the plan (waf#61). The address of the caller is pseudonymised like the calls'; the events are kept as long as the calls.

Rollups and retention​

The calls are kept 30 days. Before they go, they are rolled up by the hour: one row per hour, workspace, API, plan, subscription, application, method, templated path and status class — calls, errors, durations (their sum and a histogram), gateway overhead, bytes. They stay hourly 90 days, then are compacted by the day — a day of UTC, one row per key, the counts summed and the histograms merged bucket by bucket: nothing is lost but the hour — and kept 400 days in all. The AI usage is kept 90 days, its tokens rolled up and compacted the same way; the raw path 7 days. Every duration is set in Gateway → Ingestion › Retention.

The rollups are made by the ingester every five minutes (APIM_INGEST_RETENTION_MS), one ingester at a time, by id, not by hour: a late event is counted in its hour, and nothing is counted twice. A call is deleted only once rolled up. Roll up and purge now runs it at once. The same run compacts the days past the hourly retention, from the oldest, a month of days at most each time; an event that arrives late in a compacted day adds an hourly row there, compacted at the next run.

A dashboard whose range starts after the last purge reads the calls themselves, exactly. Before, it reads the rollups plus the calls not rolled up yet: its counts are exact, its buckets an hour at least, its percentiles read from the histograms (an approximation, marked ≈), its paths templated. A range that reaches the daily rollups is read by whole days: it starts with its first whole day, its buckets a day at least. The request log is the calls: it goes back as far as they are kept.

Why the compaction: an hourly row per key and per hour makes the history heavy — a workspace of thirty subscriptions calling four paths gives two million rows over a year, and its twelve-month dashboard read them in about five seconds. Compacted past 90 days, the same year holds four hundred thousand rows, most of them the last two months, and the same dashboard takes under a second, its figures identical.

Dashboards​

They speak the catalogue's vocabulary — APIs, plans, applications — not the infrastructure's.

  • Console → Observability, and the Analytics tab of each API and application. One row of filters scopes everything below it, and lives in the URL, so a filtered view is a bookmark: the timeframe — from the last 5 minutes to the last year, or a custom range — the API, its plan, the application, the status class (2xx to 5xx); a refresh, and an auto-refresh every 10 seconds to 5 minutes.
    • The figures: calls and the applications that made them, requests per second, errors and server errors, latency — average, minimum, maximum, p95 — and the overhead of the gateway, data.
    • Over time: the responses, split into successes, client errors (4xx) and server errors (5xx, and the failures of the gateway); the latency (average, p95, gateway overhead); the hits of the first four applications and APIs, the others folded into one gray line. The buckets follow the range — a minute for an hour, a quarter of an hour for a day, an hour for three days, a day for three months — and the empty ones are shown: a bucket without calls has no latency, not a zero one.
    • The tops: APIs by calls, by server errors and by latency; applications by calls and by latency; plans; status codes; hosts; endpoints by templated path, and paths as they were called.
    • Every chart has its legend and a table view. View the logs opens the request log with the same filters. A range read from the rollups keeps its counts exact; it has no minimum, no maximum and no percentile per bucket, nor the hosts or the paths as they were called — the dashboard says so. Reading the request log is recorded in the audit trail: it is personal data.
  • Console → Observability → Logs: the request log — the calls themselves, as far back as they are kept — with the filters of the dashboards, and its own: the method, a part of the path, the client id (from a call), a free search (path, status, host, client id, address, request id). A call opens on its detail: its request id, host, API, plan, application, client id, address, user agent, and where its time went (backend, gateway overhead). Export as CSV downloads the filtered calls, the most recent first (50,000 at most); a cell a spreadsheet would run as a formula is quoted as text. Reading the log and exporting it are recorded in the audit trail (analytics.calls.read, analytics.calls.export): it is personal data. In the admin API: GET …/analytics/calls?status=&method=&path=&client=&plan= and GET …/analytics/calls/export.
  • One request id, end to end. The gateway gives every call an id, Otoroshi-Request-Id: the caller gets it back in the response, the backends receive it with the request (the projection adds Otoroshi headers in to the flows of an API, unless its settings say otherwise: Settings › Correlation), and the request log keeps it — a request id a consumer or a backend quotes finds its call in the search of the request log.
  • Console → Observability → Security, and the Analytics tab of an API whose plans carry the threat protection: the security events by category, action and plan, how many were refused or masked, the latest ones. Reading them is recorded in the audit trail: they carry the address of the caller.
  • Portal → Usage: the same, restricted to the consumer's own applications.
  • Portal → My apps: the live quotas of each key, as the gateway counts them (read-only, never on the request path).