Telemetry (OpenTelemetry)
PromptGate sends traces, metrics and logs to an OpenTelemetry Collector — or straight to any backend that takes OTLP over HTTP: Grafana Tempo, Mimir and Loki, Jaeger, Honeycomb, Datadog, Elastic, New Relic, Dynatrace. Spans carry the OpenTelemetry GenAI conventions, so LLM dashboards built for them show PromptGate’s traffic without mapping.
What telemetry can do
Section titled “What telemetry can do”| feature | does | |
|---|---|---|
| a span per request | model requests, MCP calls and API Gateway calls, with duration, status and the request’s facts | attributes |
| one trace end to end | joins the caller’s trace (W3C traceparent) and passes it on to providers and APIs |
trace context |
| a span per provider call | every attempt, the ones a fallback replaced too, with why it didn’t serve | trace context |
| GenAI conventions | gen_ai.operation.name, gen_ai.provider.name, gen_ai.request.model, gen_ai.response.model, gen_ai.usage.* |
attributes |
| PromptGate’s own facts | cost, key, end user, endpoint, fallback, cache hit, guardrail findings (as a span event) | attributes |
| errors | 5xx answers are error spans with the reason; 4xx carry error.type |
status |
| metrics | every Prometheus metric pushed as OTLP — no scrape, no open port | metrics |
| logs | every request as a log record linked to its span — the SIEM and warehouse path | logs |
| sampling | trace a share of requests; a caller’s decision wins | telemetry.otlp.traces.sample |
| protobuf or JSON | OTLP/HTTP with gzip; protobuf by default | telemetry.otlp.protocol |
| headers | a backend’s API key, from the environment | telemetry.otlp.headers |
| off the request path | built and sent in batches in the background, retried on 429/5xx; nothing waits for the collector | delivery |
Everything in one config:
telemetry: service_name: promptgate # service.name; default promptgate otlp: endpoint: http://otel-collector:4318 # OTLP/HTTP base URL; /v1/traces, /v1/metrics, /v1/logs are appended protocol: http/protobuf # or http/json headers: Authorization: "Bearer ${OTLP_TOKEN}" # never logged or shown traces: enabled: true # default sample: 0.25 # share of requests traced, 0 to 1; default 1 metrics: enabled: true # default interval: 60s # 10s to 1h; default 60s logs: enabled: true # default falseTelemetry is off until telemetry.otlp.endpoint is set; then traces
and metrics are on, logs off. Changes apply on restart. The start banner
shows where telemetry goes and which signals.
What a span carries
Section titled “What a span carries”The request’s span is a server span named like the operation (chat gpt-5, tools/call search, POST stripe), from the request’s start to
its last byte, on a resource with service.name, service.version and
host.name. Provider calls below it are client spans with
gen_ai.provider.name, gen_ai.request.model,
http.response.status_code and, when they didn’t serve, error.type.
| attribute | on | value |
|---|---|---|
gen_ai.operation.name |
model requests | chat, embeddings, text_completion |
gen_ai.provider.name |
model requests | the provider PromptGate sent it to: openai, anthropic, … |
gen_ai.request.model, gen_ai.response.model |
model requests | the model asked for, and the one that answered |
gen_ai.usage.input_tokens, …output_tokens, …cache_read.input_tokens |
model requests | tokens as the provider counted them |
http.route, http.response.status_code |
all | the API path and the answer’s status |
mcp.method.name, gen_ai.tool.name, promptgate.mcp.server |
MCP gateway | tools/call, the tool, the server |
http.request.method, url.path, promptgate.api |
API Gateway | the call and the API |
promptgate.cost_usd |
priced model requests | what it cost |
promptgate.key, user.id |
when known | the pg_ key’s name, the end user as logged (hashed with users.log: hashed) |
promptgate.endpoint, ….version, promptgate.cache_hit |
AI Gateway endpoints | which endpoint, which version, answered from the cache |
promptgate.fallback |
after a fallback | the attempts that failed first |
promptgate.stream, promptgate.ttfb_ms |
model requests | streamed, time to the first byte |
promptgate.guardrails (+ span event) |
when a guardrail found something | kinds and counts — never the matched text |
error.type |
4xx and 5xx | the status code |
No span holds a prompt, an answer, a provider key or a pg_ key.
Trace context
Section titled “Trace context”A request that comes with a W3C traceparent header becomes part of the
caller’s trace: PromptGate’s span is a child of the caller’s, and the
caller’s sampling decision wins over traces.sample (a sampled caller is
always traced, an unsampled one never). Without the header a new trace
starts.
Every call to a provider is a client span below the request’s span, and
the provider gets its own traceparent (and the caller’s tracestate),
so a provider or proxy that traces too lands in the same trace. With a
fallback, each attempt is its own span: the one that
failed is an error span with error.type (529, unreachable), the
one that answered isn’t.
| surface | joins the caller’s trace | passes it on |
|---|---|---|
| model requests (agent proxy, AI Gateway) | yes | to the provider, one span per attempt |
| API Gateway | yes | to the API, with PromptGate’s span as parent |
| MCP gateway | yes | not yet — local servers have no headers, and one POST may carry several messages |
With telemetry off, PromptGate adds nothing: a client’s traceparent
reaches providers as it was sent.
Status
Section titled “Status”As for HTTP servers in the OpenTelemetry conventions: a 5xx answer — a
provider that failed, an unreachable upstream — is an error span with
the reason as its message. A 4xx is the client’s problem (a refused key,
a guardrail block, a budget): the span stays unset and carries
error.type.
Metrics
Section titled “Metrics”The same metrics the Prometheus endpoint serves — with
the same names and labels, so a dashboard finds the same series on
either path — pushed every interval: counters as cumulative monotonic
sums (since the gateway started), gauges as gauges, histograms with
their buckets; _seconds metrics carry the unit s. They are pushed
once more when PromptGate stops. metrics.listen isn’t needed for this;
set both to have both.
With logs.enabled, every request becomes a log record — sampled for
traces or not: promptgate.request as event name, a one-line body
(/v1/chat/completions 502 openai/gpt-5 31ms — provider openai is unreachable), the span’s attributes, severity INFO, WARN for 4xx, ERROR
for 5xx, and the trace and span ids when the request was traced, so a
backend jumps from the record to the trace. No record holds a prompt or
an answer. This is the path into a SIEM or a warehouse: the collector
forwards to ClickHouse, Elastic, Splunk or S3.
Delivery
Section titled “Delivery”Spans and log records are queued (8,192 each at most) and sent in
batches of up to 512, at least every 2 seconds, gzipped. A collector answering 429, 502, 503 or
504, or not answering at all, is retried five times with a growing pause
(honouring Retry-After); other answers are not retried. When the queue
is full, new items are dropped rather than slowing requests down. On
shutdown PromptGate sends what is queued, waiting at most 5 seconds.
promptgate_otlp_items_total{signal, result} counts what was sent,
dropped and given up, per signal.
What it costs: about 0.1 µs on the request path (the trace ids and a queue send) and about 20 µs of CPU per request in the background with traces, logs and metrics on; streamed answers are as fast as without. At saturation (55,000 requests per second on one laptop) 0.006 % of spans were dropped (benchmark).
The encoding is PromptGate’s own — no OpenTelemetry SDK — and is checked
against the OpenTelemetry Collector in CI (scripts/otlp-collector.sh).