Request tracing
Gateway tracing records a step-by-step execution trace for each inference request. Each trace captures what happened at every stage of the request pipeline — model resolution, routing decisions, guardrail results, upstream calls, and the final response delivered to the client. Traces are linked to log entries via the trace_id field.
Tracing is opt-in and has no effect on request latency. All writes are fire-and-forget.
Enabling tracing
Proceed as follows to enable tracing on a gateway:
- Open the gateway in Organisation › AI setup › Gateways.
- The gateway page appears on the Endpoint & keys tab.
- Click on the Edit button in the Gateway card header.
- The gateway settings page opens (
…/gateways/<gateway>/settings).
- The gateway settings page opens (
- Open the Tracing tab and use the Request Tracing block.
- Toggle the Enable request tracing control to on.
- If required, toggle Include message bodies in trace to record raw request content and web-search previews in the trace steps.
- Enable this for debugging only. It stores prompt text, response previews, and web-search queries in the trace table.
- When it is off (the default), these fields are omitted and the request and web-search steps record only metadata (message counts, body sizes, status).
- If required, set the Retention (hours) field. Note: this per-gateway value is stored but does not change how long traces are kept — trace retention is a single deployment-wide setting (default 48 hours); see Trace retention below.
- Click on the Save Changes button in the bar at the bottom of the page.
- The updated configuration is applied within seconds.
The Tracing tab of the gateway settings page
-> Tracing is active for all subsequent requests through this gateway.
Alternatively, apply the configuration via the API:
curl -X PATCH https://<your-gateway-host>/admin/v1/gateways/{id} \
-H "Content-Type: application/json" \
-d '{"config": {"tracing": {"enabled": true}}}'
The full tracing configuration block:
| Field | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | false |
Activates request tracing for this gateway. |
include_bodies |
boolean | false |
Includes raw content in the trace-step content fields: request_received/leg1_request/leg2_request (messages, tools), leg1_response/leg1_direct_answer (body_preview), search_result (queries), fetch_attempt (urls), leg2_response (content, raw_content), tool_call (args), tool_result (filename), upstream_error (resp_body), provider_quota_exhausted and capability_mismatch (body), file_sentinel_recovery, file_claim_no_artifact (filename), reserve_download (file_id, filename), silent_write_file_drop (dropped_file, raw_content), silent_tool_call_drop and empty_suppressed_no_tool (raw_content), rag_rank (order), and the file names on turn_committed (files[].filename). Enable only for debugging — this stores prompt and response text in the trace table. Bodies are stored only when ALL of these hold: include_bodies is on, the gateway's log_payloads is on (absent counts as on), the request did not send x-aig-collect-log-payload: false (or another opt-out/malformed value, see Request logs), and the turn is not private (ghost). include_bodies is a debug opt-in on top of the request-log payload rule, never a way around it. When any condition fails, these fields are omitted and the steps record only metadata (lengths such as content_len, counts, ids, status, provider/model). The Playground and agent-invoke traces follow the same rule: they carry bodies when the gateway opted in and the gate is open. A private (ghost) conversation is always metadata-only regardless of this flag: its trace row is still written for operations and debugging, but no prompt, response, tool argument, query, filename, or preview content is persisted in it. Agent-invoke requests discard caller x-aig-* headers, so the per-request header cannot opt out there; the gateway log_payloads switch does. |
Trace retention
Stored gateway traces are purged automatically, so the trace table does not grow without bound. Retention is deployment-wide, not per-gateway: a background job on the gateway deletes gateway traces older than the retention window once per hour.
The window is a deployment setting configured by your operator (default 48 hours, minimum 1). It is not part of a gateway's configuration.
Pipeline step reference
Steps are recorded in sequence order. Only steps that are reached for a given request appear in the trace. For example, a cached response does not produce upstream_request or upstream_response steps.
💡 Note: The steps below are the common ones a reader meets most often; the list is not exhaustive. The pipeline emits roughly thirty step types in total (retries, guardrail phases, tool-loop rounds, delegation, and more), and new steps are added as the pipeline grows.
request_received
Recorded immediately after the request body is parsed.
| Field | Description |
|---|---|
model |
Model name as received from the client (before normalisation). |
provider |
Provider resolved from the URL path. |
messages_count |
Number of messages in the request body. |
streaming |
Whether the client requested a streaming response. |
size_bytes |
Raw request body size in bytes. |
is_compat |
Whether the request arrived on the OpenAI-compatible endpoint. |
messages |
Full message array (only present when include_bodies: true). |
request_transformed
Recorded only when the model or provider changes during normalisation (e.g. compat endpoint provider inference, provider-prefix stripping).
| Field | Description |
|---|---|
model_before |
Model name before normalisation. |
model_after |
Model name after normalisation. |
provider_before |
Provider before normalisation. |
provider_after |
Provider after normalisation. |
routing_applied
Recorded when a routing rule matches and changes the provider or model.
| Field | Description |
|---|---|
rule_id |
ID of the matched routing rule. |
provider_before |
Provider before routing. |
model_before |
Model before routing. |
provider_after |
Provider after routing. |
model_after |
Model after routing. |
guardrail_result
Recorded after the guardrail pipeline completes.
| Field | Description |
|---|---|
verdict |
"safe", "unsafe", or the guardrail verdict string. |
blocked |
true if the request was blocked. |
detector |
Name of the detector that fired (if blocked). |
latency_ms |
Time spent in the guardrail pipeline. |
upstream_request
Recorded immediately before each upstream provider call.
| Field | Description |
|---|---|
attempt |
Attempt number (1 = first try). |
provider |
Provider being called. |
model |
Model being called. |
url |
Request URL sent to the provider (auth key stripped). |
upstream_response
Recorded after each upstream provider response is received.
| Field | Description |
|---|---|
attempt |
Attempt number. |
provider |
Provider that responded. |
status |
HTTP status code. |
latency_ms |
Time between upstream request and response. |
input_tokens |
Prompt tokens from the provider usage object. |
output_tokens |
Completion tokens from the provider usage object. |
upstream_error
Recorded when an upstream call fails with a network error (not an HTTP error response).
| Field | Description |
|---|---|
attempt |
Attempt number. |
provider |
Provider that failed. |
error |
Error message string. |
response_delivered
Recorded after the response is sent to the client.
| Field | Description |
|---|---|
streaming |
Whether the response was streamed. |
provider_status |
HTTP status code from the upstream provider. |
body_size |
Response body size in bytes (non-streaming). |
compat |
Whether the response was re-encoded for the compat endpoint. |
Web search steps
These steps appear when web search is enabled on the gateway.
| Step | Description |
|---|---|
leg1_request |
First inference call to extract search queries. Records messages_count/tools_count; the raw messages/tools only when include_bodies is on. |
leg1_response |
Response from the first call. Records status/body_len; the raw body_preview only when include_bodies is on. |
leg1_direct_answer |
Recorded when the model answers directly without triggering a search. Records body_len; the raw body_preview only when include_bodies is on. |
search_result |
Queries sent and snippets returned from the search provider. Records queries_count and per-result sizes/URLs; the raw queries only when include_bodies is on. |
fetch_attempt |
URLs selected for full-page fetching. Records url_count; the raw urls only when include_bodies is on. |
fetch_result |
Fetch outcome for each URL. Records ok/text_len; the raw url and page preview only when include_bodies is on. |
leg2_request |
Second inference call with search context injected. Records messages_count; the raw messages only when include_bodies is on. |
leg2_response |
Final response from the second call. Records content_len (and raw_len when the relay changed the text); the raw content/raw_content only when include_bodies is on. |
Tool execution steps
These steps appear when the model calls a tool (for example the code interpreter) during an agentic turn.
| Step | Description |
|---|---|
tool_call |
One tool invocation the model requested. Records round/tool; the raw args only when include_bodies is on. |
input_files_staged |
Code-interpreter data-file staging outcome. Records requested/derived/staged/notes/auto/image counts only (staged counts data files; the turn's attached picture is never in it, image is 1 when that picture was staged as /input/attached_image.*; derived is how many of the requested names the gateway derived from /input/<name> references in the code because the model passed no input_files, so requested - derived is what the model itself asked for; auto is how many attached or project files were put in /input automatically, without being requested) — filenames and bytes are never stored in the trace. notes counts drop notes, not files: one note can cover several requested files, so requested is not necessarily staged plus notes. |
tool_result |
The result returned to the model. Records round/tool/chars; the produced filename only when include_bodies is on. |
loop_terminated |
The agentic loop ended early. Records the termination reason and its details. |
RAG ranking step
This step appears when the model calls the knowledge-search tool.
| Step | Description |
|---|---|
rag_rank |
Retrieval ranking for one knowledge-search call, including the cross-encoder rerank stage (on by default). Records mode (dormant when the rerank is switched off or there were fewer than two passages to order, reranked when the reranker reordered the results, or fallback when a configured reranker was unavailable and the fused order was kept), configured (whether a reranker model is set, i.e. the rerank is switched on), fused_n (candidate passages after hybrid fusion), kept (passages served after any rerank trim), and sent (passages sent to the reranker). The ranked document identifiers (order) only when include_bodies is on. |
Linking traces to log entries
When gateway tracing is enabled, each entry in the log list (GET /admin/v1/logs) contains a trace_id field. Fetching a single entry by id does not return it. Use the trace_id from the list to retrieve the full execution trace.
Proceed as follows to retrieve the trace for a log entry:
-
List the logs to obtain the
trace_idof the entry.- Each entry in the response contains a
trace_idfield, for example"trc_abc123".
- Each entry in the response contains a
-
Fetch the full trace using the
trace_id.
-> The full execution trace for the request is returned.
💡 Note:
trace_idisnullin log entries when tracing was not active for that request.
Playground requests that pass authentication and the IP allowlist always produce traces, regardless of the gateway tracing config; a playground request refused there has no trace (trace_id is null in its log entry). Playground traces have source: "playground" and are accessible via the same GET /traces/{id} endpoint.
Configuring OTLP export
The gateway exports distributed traces as OpenTelemetry Protocol (OTLP) spans to any OpenTelemetry-compatible backend — Jaeger, Grafana Tempo, Datadog, Honeycomb, and others. OTLP export is independent of the internal pipeline trace described above.
W3C traceparent propagation
The gateway reads an incoming traceparent header from the client (if present) and propagates the trace context to upstream LLM providers. This allows end-to-end trace correlation across your services, the gateway, and the provider. When the gateway initialises tracing for a request — whether from an incoming traceparent or by generating new IDs — it injects a traceparent header into the upstream provider request.
OTLP/HTTP span export
After each request, the gateway emits a root span (SERVER) and, when an upstream call was made, a child span (CLIENT) to your OTel collector. Delivery is fully asynchronous and never adds latency. A failed delivery (collector not reachable, authentication refused, time-out) is logged and recorded for the platform operator; the inference request is not affected. Numeric span attributes (token counts, durations) are exported exactly, never rounded to fewer digits.
Configuration
Add otlp_endpoint to your existing tracing block:
{
"tracing": {
"enabled": true,
"otlp_endpoint": "https://otel-collector.example.com:4318",
"service_name": "ai-gateway",
"headers": {},
"sample_rate": 1.0,
"include_bodies": false
}
}
| Field | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | false |
Activates internal pipeline tracing |
otlp_endpoint |
string | — | Base URL of your OTel collector, e.g. https://otel-collector.example.com:4318. Must be a public https:// address (see Destination policy). The gateway appends /v1/traces and sends the spans as OTLP/HTTP JSON (POST). Setting this enables OTLP export. |
service_name |
string | ai-gateway |
service.name resource attribute on all emitted spans |
headers |
object | {} |
Extra HTTP headers to include in the OTLP request (e.g. auth tokens for managed collectors) |
sample_rate |
number | 1.0 |
Fraction of requests to export (0.0 = never, 1.0 = always) |
include_bodies |
boolean | false |
When true, adds aig.request_size_bytes to spans |
💡 Note:
enabled: truealone activates only the internal pipeline trace (playground / Traces API). Settingotlp_endpointenables OTLP export and implies tracing is active for that gateway — export runs onotlp_endpointindependently ofenabled, so a gateway can export spans withenabled: false.🔒
tracing.headersis write-only. It carries collector credentials, so no read returns it: the gatewayconfigshowsheaders_set(boolean) instead. APATCHthat omitsheaderskeeps the stored headers;{},""ornullclears them (no secret change is recorded when neither side held any); a non-empty object replaces them. Changingotlp_endpointwithout re-sendingheadersis400config_credential_required. The headers are stored encrypted, as one value.💡 Note: The four OTLP-export fields (
otlp_endpoint,service_name,headers,sample_rate) are configured via the Admin API and have no control on the gateway settings page. The page exposes onlyenabled/include_bodies/ retention, and preserves the OTLP fields untouched on save — editing an unrelated gateway setting never wipes your export configuration, and toggling "enable tracing" off on the page does not stop OTLP export (removeotlp_endpointvia the API to do that).
Destination policy
The gateway sends spans from its own network position, so the collector address is checked like a webhook URL:
otlp_endpointmust be anhttps://URL with a public DNS name. IP addresses (in any spelling),localhost, single-label hosts such ashttp://otel-collector:4318, user name / password in the URL, and a query or fragment are refused. The gateway appends/v1/tracesitself; trailing slashes are ignored.- The name must resolve to public addresses only. Private, loopback, link-local, cloud-metadata and other internal ranges are refused, and so is a name that does not exist (one fixed message for both).
- The check runs when you save the gateway and again before spans are sent. The gateway connects to the address it just verified, so a name that later changes to an internal address cannot redirect the export. Verified addresses are cached for 30 seconds per worker.
- A destination that is refused at send time (for example a stored value from before this rule) exports nothing. The gateway logs a warning and records a delivery fault in the error triage list, at most once per minute per gateway.
- An
otlp_endpointthat is unchanged from the stored value is accepted on an unrelated save, so an older gateway is never locked out of editing; changing it is checked. Clearing it (nullor"") is always allowed. headersmust be an object of at most 32 entries, and at most 8192 bytes once serialized as JSON (larger is 400invalid_tracing_headers). Names must be valid HTTP header names, values must be strings of at most 4096 bytes without control characters.Host,Content-Length,Transfer-Encoding,Connection,Content-TypeandUser-Agent(in any letter case) are set by the gateway and are refused (400invalid_tracing_headers, formerlytracing_headers_invalid); a stored entry of that kind is dropped at send time and logged (at most once per minute per gateway).
A self-hosted collector on a private network is not reachable from the gateway. Expose it on a public https:// name (with headers for authentication), or use a managed backend.
Span model
Each exported trace contains up to two spans:
| Span | Kind | When emitted | Name |
|---|---|---|---|
| Root span | SERVER (2) | Every request | inference |
| Upstream span | CLIENT (3) | Only when an upstream LLM call was made | upstream.<provider> |
The parentSpanId of the upstream span is the spanId of the root span, forming a parent-child relationship.
Root span attributes (GenAI semantic conventions)
| Attribute | Type | Description |
|---|---|---|
gen_ai.system |
string | LLM provider (openai, anthropic, …) |
gen_ai.request.model |
string | Model name |
gen_ai.usage.input_tokens |
integer | Prompt token count |
gen_ai.usage.output_tokens |
integer | Completion token count |
gen_ai.request.cost_usd |
double | Estimated inference cost |
http.status_code |
integer | HTTP status returned to the client |
aig.tenant_id |
string | Tenant identifier |
aig.gateway_id |
string | Gateway identifier |
aig.cached |
boolean | Whether the response came from cache |
aig.blocked |
boolean | Whether the request was blocked |
aig.blocked_by |
string | Block reason category (when blocked) |
aig.upstream_attempts |
integer | Provider dials attempted (emitted when > 0) |
Upstream span attributes
| Attribute | Type | Description |
|---|---|---|
gen_ai.system |
string | Provider |
gen_ai.request.model |
string | Model |
http.status_code |
integer | Provider HTTP status |
aig.upstream_latency_ms |
integer | Provider round-trip latency |
aig.upstream_attempts |
integer | Retry count |
aig.fallback_provider |
string | Fallback provider (when failover occurred) |
aig.fallback_model |
string | Fallback model (when failover occurred) |
Sampling
Use sample_rate to reduce export volume for high-traffic gateways:
This exports roughly 10 % of requests. Sampling is applied at export time, after the request completes: when the random draw exceeds sample_rate, the export is skipped and no span is built at all — nothing is assembled and then discarded. There is no head-based sampling; every request processes normally.
Configuration examples
The following examples show how to configure OTLP export for common backends.
Jaeger (all-in-one)
Grafana Tempo
{
"tracing": {
"otlp_endpoint": "https://tempo.example.com:4318",
"service_name": "ai-gateway-prod"
}
}
Datadog OTLP endpoint
{
"tracing": {
"otlp_endpoint": "https://otlp.datadoghq.example.com:4318",
"headers": { "DD-API-KEY": "your-api-key" },
"service_name": "ai-gateway"
}
}
Honeycomb
{
"tracing": {
"otlp_endpoint": "https://api.honeycomb.io",
"headers": { "x-honeycomb-team": "your-api-key" },
"service_name": "ai-gateway"
}
}