feat(server): export HTTP request metrics via OTLP - #1561
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 537187897f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9caa8acb2f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Problem
The lifecycle Server already owns an OpenTelemetry
MeterProviderand OTLP HTTP exporter, butmainonly exports the SDK-reportedopensandbox.sandbox.create.durationhistogram. Direct REST clients, authentication failures, validation errors, unmatched routes, and other Server HTTP traffic therefore have no generic request-rate, error-rate, or latency signal in the Server OTLP stream.This is deliberately separate from #1408 / #1412, which instrument lifecycle business operations, and narrower than the closed, unmerged #1185 Server+Controller metrics/traces proposal.
Minimal reproduction
[otel]for the Server and point it at an OTLP metrics collector.GET /v1/sandboxes, then also send a request that returns 401, 404, or 422.Before this change, the collector may receive SDK-reported creation latency, but it receives no generic HTTP request metric for those requests.
Root cause
The existing Server OTEL integration creates only the SDK creation-duration instrument. The FastAPI application has no request metrics middleware and does not record matched route templates or response status codes.
Change
server.http.request.durationhistogram in milliseconds through the existing ServerMeterProvider;http_method, matchedhttp_route, andhttp_status_code;http_route=unknownwhen routing never resolves, including early auth failures;[otel].enabled = falseand contain recorder failures;The histogram count provides request volume/QPS, status-code dimensions provide error rate, and buckets provide latency percentiles without a separate request counter.
Tests
uv run pytest tests/test_http_metrics.py tests/test_metrics_api.py -q— 17 passeduv run pytest -q— 1407 passeduv run ruff check— passedcorepack pnpm@9.15.0 docs:build— passed./scripts/verify-license.sh— passedserver.http.request.durationwith the expected unit, count, and bounded attributesFull-repository
uv run pyrightis not currently a green baseline onmain(1386 existing errors); the files and tests changed here pass the targeted check.Compatibility and security impact
This is additive. It changes no OpenAPI contract, SDK, CLI, CRD, Helm value, listener, port, or authentication behavior, and adds no dependency or configuration key. With OTEL disabled, request behavior is unchanged apart from a no-op middleware call.
Raw paths, query strings, sandbox IDs, tenant IDs, API keys, and request/response bodies are never metric attributes. Route templates are application-defined and bounded. Metric recording and exporter failures cannot change an HTTP response.
Existing Issue
Fixes #1560.