Distributed Tracing
Zerq can send OpenTelemetry traces for every gateway, AI Gateway, MCP and management API request, and for workflow runs, to any OTLP-compatible backend: Grafana Tempo, Jaeger, Honeycomb, Datadog, New Relic, Elastic, Dynatrace, or an OpenTelemetry Collector in front of them.
A gateway trace shows where the time went: authentication, policies, cache, and the call to your upstream service. Because Zerq continues the caller's trace and passes it on to the upstream, a single trace can span the client application, the gateway and your backend services.
Turn it on
Set the standard OpenTelemetry variables on the backend:
| Variable | Default | Description |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | (unset, tracing off) | OTLP/HTTP base URL, for example http://otel-collector:4318. Spans go to {endpoint}/v1/traces. |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | (unset) | Full traces URL; overrides the base URL. |
OTEL_EXPORTER_OTLP_HEADERS | (unset) | Headers sent with every export, key=value,key2=value2 (for example a vendor API key). |
OTEL_SERVICE_NAME | zerq | service.name of the spans. Use one name per environment or region if you like. |
OTEL_TRACES_SAMPLER_ARG | 1 | Share of new traces to keep, from 0 to 1. Sampling is parent-based: when a caller sends a sampled traceparent, the request is always traced. |
OTEL_RESOURCE_ATTRIBUTES | (unset) | Extra resource attributes, for example deployment.environment=prod. |
Tracing is off when no endpoint is set and then adds no overhead.
What is traced
| Span | Kind | Name | Key attributes |
|---|---|---|---|
| Gateway request | server | GET /orders/{id} (proxy path template) | http.route, http.response.status_code, zerq.collection, zerq.collection_id, zerq.client_id and zerq.profile_id (only when authentication verified them), zerq.request_id, client.address |
| Upstream call | client | GET | server.address, server.port, url.full (without the query string), http.response.status_code, zerq.proxy_id |
| AI Gateway request | server | POST /llm/v1/chat/completions | gen_ai.request.model, gen_ai.response.model, token usage, zerq.ai.provider, zerq.ai.outcome, zerq.cost_usd and more; see AI Gateway Observability |
| AI provider attempt | internal | chat gpt-4o | gen_ai.system, zerq.ai.provider, zerq.ai.model; one per provider tried, failed attempts marked as errors |
| Workflow run | internal | workflow http_trigger | zerq.workflow.trigger. A child of the gateway request for gateway workflows and of the AI request for guardrail workflows; cron, Kafka and IMAP runs start their own trace. |
| Workflow node | internal | workflow node http_request_node | zerq.workflow.node_id, zerq.workflow.node_type |
| MCP request | server | POST /mcp | zerq.server (mcp_gateway; Management MCP requests are management API requests) |
| MCP tool call | internal | tools/call execute_endpoint | mcp.tool.name. The tool's call to the gateway or management API continues the trace. |
| Management API request | server | PUT /api/v1/proxies/:id | http.route, http.response.status_code, zerq.request_id |
| Outbound HTTP call | client | POST | Calls to AI providers, workflow HTTP nodes, MCP tool calls, guardrail connectors, budget alert webhooks and Langfuse made while handling a request. They carry a traceparent header. |
| MongoDB command | client | proxies.find | Only inside a request trace (background work does not create traces). Gateway lookups of clients, profiles, collections and proxies appear when they miss the cache. |
Requests that match no proxy are named GET unmatched. Responses with status 5xx mark the span as an error; 4xx responses do not (they are the caller's error).
A failed span records its error as an exception event (exception.type, exception.message). When the error is a transport error, the URL in the message is reduced to scheme, host and path before it is exported. Like url.full, it never contains the query string, which can carry an upstream API key injected with key_in=query, or user name and password. This applies to upstream calls, outbound HTTP calls, MCP tool calls and server spans.
Trace context
- Incoming: if the caller sends a W3C
traceparentheader, the gateway span joins that trace. - Outgoing: the upstream request gets a
traceparentfor the gateway's upstream span (it replaces anytraceparentthe caller sent), so your service's spans become children of the gateway. - Response: every response carries
X-Trace-IDwith the trace ID. Callers can quote it to support.
Correlating logs, metrics and traces
The trace ID is recorded everywhere the request leaves a mark:
- Request logs have a Trace ID (filter by it in Request Logs, or with
GET /api/v1/logs?trace_id=<id>). - AI logs have a Trace ID (filter by it in AI Logs, or with
GET /api/v1/ai/logs?trace_id=<id>). - Audit logs have a
trace_idfor management changes. - Backend JSON logs have
trace_idandspan_idon lines written while handling a request, and the access log hastrace_id. - Streamed logs: request, audit and AI log entries sent by log streaming carry the trace ID.
- Metrics: the gateway and AI latency histograms carry the trace ID as an exemplar, so Grafana can open an example trace from a latency spike.
To turn trace IDs in the management UI into links, set NEXT_PUBLIC_TRACE_URL_TEMPLATE on the frontend to your tracing UI's trace URL with {traceId}, for example:
# Grafana (Tempo datasource uid "tempo")
http://grafana:3000/explore?left={"datasource":"tempo","queries":[{"refId":"A","queryType":"traceql","query":"{traceId}"}]}
# Jaeger
https://jaeger.example.com/trace/{traceId}
The observability stack wires all of this together with Grafana, Tempo, Loki and Prometheus.
Logging format
Backend logs are JSON lines. ANSI colours are only added when stdout is a terminal or LOG_COLOR=true, so logs shipped to Loki, Splunk or Elastic stay valid JSON. Set LOG_COLOR=false to force plain output.