Log Streaming and Retention
Zerq stores request logs and audit logs in MongoDB, where the management UI reads them. For a SIEM or a central log platform, Zerq can also stream every entry as it is written, and delete old entries on a schedule.
Streaming destinations
Streaming is configured with environment variables on the backend. Turn on any combination of destinations; each entry goes to all of them.
| Destination | Variables | Notes |
|---|---|---|
| OpenTelemetry (OTLP/HTTP logs) | LOG_STREAM_OTLP_ENDPOINT, optional LOG_STREAM_OTLP_HEADERS | Collector base URL (for example http://otel-collector:4318) or the full …/v1/logs URL. Use it for Grafana Loki, Elastic, Datadog, New Relic, Dynatrace, or any backend behind an OpenTelemetry Collector. |
| Splunk HTTP Event Collector | LOG_STREAM_SPLUNK_HEC_URL, LOG_STREAM_SPLUNK_HEC_TOKEN, optional LOG_STREAM_SPLUNK_INDEX | URL of the event endpoint, for example https://splunk:8088/services/collector/event. Events use source zerq and sourcetype zerq:request or zerq:audit. |
| Webhook | LOG_STREAM_WEBHOOK_URL, optional LOG_STREAM_WEBHOOK_HEADERS | Each batch is POSTed as a JSON array of flat events. |
Headers are written as Name=value,Name2=value2.
| Variable | Default | Description |
|---|---|---|
LOG_STREAM_TYPES | request,audit,ai | Which logs to stream: gateway request logs, audit logs and AI Gateway request logs. |
LOG_STREAM_INCLUDE_BODIES | false | Also stream request/response headers and bodies (after redaction). Leave off unless the destination is approved for payload data. |
LOG_STREAM_QUEUE_SIZE | 10000 | Entries held in memory while destinations are slow or down. |
What a streamed entry contains
Every entry has a timestamp, a severity (INFO, WARN for 4xx, ERROR for 5xx), a one-line message and the trace ID when tracing is on, so log lines link to traces.
Request log entries (message GET /shop/orders/42 200 18ms): http.request.method, url.path, http.response.status_code, zerq.latency_ms, client.address, zerq.client_id, zerq.profile_id, zerq.collection_id, zerq.request_id, zerq.target_url (credential query parameters masked) and error.message.
Audit entries (message [email protected] update proxy (200)): zerq.actor_id, zerq.actor_type, zerq.resource_type, zerq.action, client.address, user_agent.original, zerq.request_id, url.full, http.response.status_code.
With OTLP, entries are grouped by resource: service.name (OTEL_SERVICE_NAME, default zerq) and zerq.log (request, audit or ai). The included Loki configuration indexes both as labels, so {service_name="zerq", zerq_log="audit"} selects audit entries.
Delivery guarantees
Streaming never slows down or fails a request. Entries are queued in memory and sent in batches every 2 seconds (or every 500 entries). A batch that fails with a network error, 408, 429 or 5xx is retried twice with backoff. Other errors (for example 401 from a wrong token) are not retried. Watch these metrics:
zerq_logs_stream_records_total{sink, result="sent"|"failed"}— delivered and lost entries per destination.zerq_logs_stream_records_total{sink="queue", result="dropped"}— entries dropped because the queue was full.
The MongoDB copy is written independently, so a streaming outage does not lose entries from the management UI. Queued entries are flushed on a graceful shutdown.
A batch that cannot be delivered is logged as a warning in the backend log. The logged error names the destination but never contains the URL's query string or user name and password, so a token in LOG_STREAM_WEBHOOK_URL, LOG_STREAM_OTLP_ENDPOINT or LOG_STREAM_SPLUNK_HEC_URL is not written to the logs. A destination URL that cannot be parsed is reported as invalid sink URL and is not retried. Prefer LOG_STREAM_OTLP_HEADERS, LOG_STREAM_WEBHOOK_HEADERS or LOG_STREAM_SPLUNK_HEC_TOKEN over tokens in the URL.
Request log levels
Each proxy chooses how much of a request its log entry stores (Request logging on the proxy's Basic Information step, or log_level in the API):
| Level | Stored |
|---|---|
| Gateway default (empty) | Whatever REQUEST_LOG_LEVEL says (default full). |
full | Metadata, request and response headers, request and response bodies. |
headers | Metadata and headers, no bodies. |
metadata | Method, path, status, latency, client, profile, collection, request and trace IDs, error. No headers or bodies. |
none | No request log entry. Metrics and traces still record the request. |
REQUEST_LOG_LEVEL also applies to requests that matched no proxy (for example rejected by authentication). REQUEST_LOG_MAX_BODY_BYTES cuts stored bodies to that many bytes and notes the original size (default 0, whole bodies). Redaction always runs first.
Changing a proxy's log level is a proxy update, so it is recorded in the audit log.
Retention
| Variable | Default | Description |
|---|---|---|
REQUEST_LOG_RETENTION_DAYS | 0 (keep) | Delete request log entries older than this many days. |
AUDIT_LOG_RETENTION_DAYS | 0 (keep) | Delete audit entries older than this many days. Check your regulatory requirements first; many require years. |
AI_LOG_RETENTION_DAYS | value saved in AI Settings (default 30) | Delete AI log entries older than this many days; 0 keeps them. When it is not set, the retention saved in AI Settings by earlier versions still applies. |
Retention runs at startup and then every hour, with the same job for all three logs. Retention is configured on the server only, so nobody can shorten it (and delete logs) from the console or the API. Deleted entries are counted in zerq_logs_retention_deleted_total{log} (request, audit, ai). To keep audit history beyond what MongoDB holds, stream audit entries to your SIEM or archive.
The backend also creates the indexes that log searches, the dashboard and retention use (on created_at, trace_id, request_id, client and collection) when it starts.