What Hivenet Router audits
The audit middleware covers HTTP requests handled by the router, including:- inference requests under
/v1/* - model-discovery requests
- administration requests under
/admin/* - authentication and quota failures
- successful and unsuccessful backend responses
GET /healthliveness probes- CORS
OPTIONSpreflight requests
Audit record format
The default file is:Audit fields
Request IDs
Hivenet Router accepts an incoming:- returned in the
X-Request-IDresponse header - stored in the audit record
- attached to the active trace span
Trace IDs
When OpenTelemetry tracing is active,trace_id contains the current span’s trace ID.
Hivenet Router also returns a W3C:
- an application request
- the JSONL audit record
- Loki logs
- a Tempo trace
Tenant and key identity
For authenticated client requests:Audit records and Prometheus labels use different empty-key conventions.Static and no-auth audit records normally use an empty
key_id, while tenant metrics use key_id="anonymous" for those requests.Agent and provider identity
For a successful local inference request:Token fields
For successful non-streaming chat requests, Hivenet Router records the usage available from the completed response. For streaming chat requests, Hivenet Router updates the audit values after the stream closes and the token meter has finished. Embedding and reranking requests currently record:Audit token values describe what Hivenet Router could account for during that request. Their precision depends on the backend response and the request type.
What is not logged
The dedicated audit record does not include:- prompt or message content
- response or completion content
- request body
- response body
- authorization header
- raw API keys
- provider credentials
- complete HTTP headers
- HTTP method
- request path
Error codes
When a request handler provides a specific Hivenet Router domain code, the audit record preserves it. Common inference codes include:
When no more specific domain code was attached, the middleware derives a fallback code from the HTTP status:
An oversized
/v1/* request can be rejected with HTTP 413 before the normal inference-handler error path. In that case, treat status_code as authoritative; the audit error_code may be a broad status-derived value rather than a dedicated request-size code.
Some administration endpoints return simpler endpoint-specific errors without attaching a domain code. Their audit record may therefore contain the broader status-derived value.
See Error codes for the inference error reference.
Configure the file path
Set the case-sensitive environment variable:Restart the router after changing
HIVENET_ROUTER_AUDIT_LOG_PATH. The audit logger does not reopen the file dynamically after an environment change.Fallback to stdout
If Hivenet Router cannot create the directory or open the file, the router still starts and writes audit JSON to standard output. It also writes an explanatory message to standard error:Bare-metal permissions
Create a protected directory for a service running ashivenet-router:
Docker Compose pipeline
The repository’s Compose stack already connects the router’s audit file to Promtail. The router writes to a named volume:Promtail configuration
The repository separates application and audit logs into two jobs. The audit job reads only the JSONL file:tenant_idstatus_codemodelerror_codelevel
Label-cardinality guidance
Tenant and model labels are useful for dashboards, but they increase the number of Loki streams. For a larger deployment, review whether these should remain indexed labels:Query audit records
All audit records
Errors
One tenant
One model
One request ID
request_id is not a Loki label, so parse the JSON field:
One trace
Slow requests
Authentication failures
Model-access failures
Provider fallback requests
Aggregate audit data
Request rate by status
status_code is a promoted label in the repository configuration, it remains available to the aggregation.
Error rate
Requests by model
Output tokens by tenant
Average latency by tenant
P95 latency
Use the Grafana audit dashboard
The provisioned dashboard is available at:- recent request records
- request rate by status
- P95 latency
- top models
- error rate
- tenant ID
- status code
- model
- error code
Correlate logs and traces
A practical investigation flow is:- Obtain the request’s
X-Request-IDortraceparentresponse header. - Search the audit logs for
request_idortrace_id. - Inspect the status, tenant, model, agent, latency, and error code.
- Open the matching trace in Tempo.
- Review router application logs for the same request ID.
- Inspect Prometheus metrics for the selected agent and model.
Source IP and proxies
Thesource_ip field comes from Gin’s client-IP resolution.
Its accuracy depends on:
- whether the router is reached directly
- which reverse proxies are trusted
- whether forwarding headers are replaced or preserved
- whether clients can send spoofed forwarding headers
source_ip as a verified user or tenant identity.
When Hivenet Router sits behind a proxy:
- restrict direct access to the router
- configure the proxy to replace untrusted forwarding headers
- review Gin’s trusted-proxy behavior for your deployment
- test the value recorded in the audit file
Retention and rotation
Hivenet Router opens the audit file when the process starts and keeps the file descriptor open. A rotation method that renames the file and creates a new one can leave the router writing to the renamed file until restart. For a simple bare-metal setup, usecopytruncate:
- Loki retention
- local audit-file retention
- backup requirements
- deletion workflows
- access controls
- storage capacity monitoring
loki_data volume removes the stored Loki data.
Privacy and governance
Audit logging can support operational investigations and evidence collection, but it does not by itself establish compliance with any law or standard. Before production use, decide:- which teams may access audit data
- how long records are retained
- whether source IP addresses should be stored
- whether tenant and model names reveal sensitive information
- how deletion and access requests are handled
- whether records must be exported to a separate security system
- how clock, integrity, backup, and incident procedures are controlled
- reverse proxies
- inference backends
- client applications
- provider APIs
- container logging
- observability agents
Troubleshooting
The audit file does not exist
Check the configured path:Audit JSON appears in application stdout
The file could not be opened, so Hivenet Router fell back to stdout. Correct the path or permissions, then restart the router.Promtail does not ingest records
Check that the shared file is visible:Loki has no audit stream
Query the labels API:A field is empty
The field may not apply to that request. Examples:- auth failure: empty tenant and key
- model-list request: empty model
- pre-routing rejection: empty agent ID
- no tracing: empty trace ID
- static key: empty key ID
- embedding or reranking: zero token counts
The request ID was replaced
Hivenet Router accepts only valid UUIDs inX-Request-ID.
Use a UUID such as:
The source IP is unexpected
Check the proxy path and forwarding headers. The recorded value may be the proxy address or a header-derived address, depending on how the router is reached and configured.Token totals are zero
Possible causes include:- the request failed before inference
- it was an embedding or reranking request
- the backend did not report usage
- streaming usage could not be measured
- the handler did not have token information for that route
Records continue in a rotated file
The router keeps the audit file open. Usecopytruncate, or restart the router after a rename-based rotation so it opens the new path.
Next steps
Hardware metrics
Review the GPU, CPU, and memory data reported by agents.
Engine metrics
Understand cache, queue, latency, and throughput metrics by backend.
Error codes
Review the structured errors recorded in audit entries.

