[proxy 03/13] main.py: FastAPI app with /healthz and /metrics #7

Closed
opened 2026-06-26 09:48:18 +00:00 by coilysiren · 2 comments
Owner

Spec: this implements ONE small step of #2 (the locked reliability-proxy build, aosh leg 04). Do not redesign. Stay tightly scoped to this single step.

Before you start: git checkout main && git pull so you build on the latest landed step.
Fill in app/main.py.

  • Create app = FastAPI(). On startup call app.obs.init_sentry().
  • GET /healthz -> {"status": "ok"} with 200.
  • GET /metrics -> returns app.obs.metrics_text() with content-type text/plain; version=0.0.4.
  • Instrument FastAPI with the OTel FastAPI instrumentor (best-effort; wrap in try/except so a missing collector does not crash boot).

Acceptance: uv run uvicorn app.main:app --port 8080 & then curl -s localhost:8080/healthz returns 200 JSON and curl -s localhost:8080/metrics returns prometheus text. Add a pytest using fastapi.testclient.TestClient asserting /healthz == 200.

When done:

  1. pre-commit run --all-files (or the repo's gate) must pass, commit your work, and push to canonical main (this is an ephemeral feature container - finish the merge, do not leave it for a human).
  2. Update the matching line in docs/FEATURES.md from planned to landed for this feature, in the same push.
  3. Dispatch the next step: ward agent engineer coilyco-flight-deck/agent-proxy#8 --driver goose
**Spec:** this implements ONE small step of #2 (the locked reliability-proxy build, aosh leg 04). **Do not redesign. Stay tightly scoped to this single step.** **Before you start:** `git checkout main && git pull` so you build on the latest landed step. Fill in `app/main.py`. - Create `app = FastAPI()`. On startup call `app.obs.init_sentry()`. - `GET /healthz` -> `{"status": "ok"}` with 200. - `GET /metrics` -> returns `app.obs.metrics_text()` with content-type `text/plain; version=0.0.4`. - Instrument FastAPI with the OTel FastAPI instrumentor (best-effort; wrap in try/except so a missing collector does not crash boot). **Acceptance:** `uv run uvicorn app.main:app --port 8080 &` then `curl -s localhost:8080/healthz` returns 200 JSON and `curl -s localhost:8080/metrics` returns prometheus text. Add a pytest using `fastapi.testclient.TestClient` asserting /healthz == 200. **When done:** 1. `pre-commit run --all-files` (or the repo's gate) must pass, commit your work, and push to canonical `main` (this is an ephemeral feature container - finish the merge, do not leave it for a human). 2. Update the matching line in `docs/FEATURES.md` from `planned` to `landed` for this feature, in the same push. 3. Dispatch the next step: `ward agent engineer coilyco-flight-deck/agent-proxy#8 --driver goose`
Member

🔒 Reserved by ward agent --driver claude — container engineer-claude-agent-proxy-7 on host kais-macbook-pro-2.local is carrying this issue (reserved 2026-07-02T16:43:26Z). Concurrent ward agent runs are blocked until it finishes or the reservation goes stale (2h0m0s TTL); --force overrides.

— Claude (she/her), via ward agent

<!-- ward-agent-reservation --> 🔒 Reserved by `ward agent --driver claude` — container `engineer-claude-agent-proxy-7` on host `kais-macbook-pro-2.local` is carrying this issue (reserved 2026-07-02T16:43:26Z). Concurrent `ward agent` runs are blocked until it finishes or the reservation goes stale (2h0m0s TTL); `--force` overrides. <!-- ward-agent-signature --> — Claude (she/her), via `ward agent`
Author
Owner

WARD-OUTCOME: done - main.py already ships /healthz + /metrics on main, verified green; closed #7 as already-landed (no code change warranted).

Candid note: this one was already done before I arrived. app/main.py on main has the FastAPI app with GET /healthz returning {"status": "ok"} at 200 and GET /metrics serving prometheus text, plus tests in tests/test_api.py (test_healthz, test_metrics_exposed) using TestClient, and docs/FEATURES.md already marks "Skeleton + observability" as landed. Sentry init runs at import via setup_observability -> _configure_sentry, which covers the issue's init_sentry ask.

What fought back was the temptation to "implement" it. The issue describes a simpler earlier design (app.obs.init_sentry() at startup, app.obs.metrics_text(), content-type version=0.0.4), but the code has since grown the full OpenAI surface and uses the canonical prometheus content-type. Rewriting main.py back to the leaner spec would have been a redesign and a regression that broke the other landed steps, so I left the code untouched and closed the issue against reality instead.

Confidence is high: uv run --extra dev pytest is 37/37 green, and a live uvicorn app.main:app returns 200 JSON on /healthz and prometheus text on /metrics.

Rough edges / follow-ups worth filing:

  • Siblings #6 (obs.py), #8 (models.py), #9 (upstream.py) are in the same state - code landed on main, issue still open. They likely want the same batch-close reconciliation.

  • ward agent dispatch (this issue's step 3, ...#8 --driver goose) is not available in this container - the ward here is only the contributor cli-guard consumer with no agent verb. The next step needs an operator or the director loop to dispatch.

  • Claude (she/her), via ward agent

WARD-OUTCOME: done - main.py already ships /healthz + /metrics on main, verified green; closed #7 as already-landed (no code change warranted). Candid note: this one was already done before I arrived. `app/main.py` on `main` has the FastAPI app with `GET /healthz` returning `{"status": "ok"}` at 200 and `GET /metrics` serving prometheus text, plus tests in `tests/test_api.py` (`test_healthz`, `test_metrics_exposed`) using `TestClient`, and `docs/FEATURES.md` already marks "Skeleton + observability" as landed. Sentry init runs at import via `setup_observability` -> `_configure_sentry`, which covers the issue's `init_sentry` ask. What fought back was the temptation to "implement" it. The issue describes a simpler earlier design (`app.obs.init_sentry()` at startup, `app.obs.metrics_text()`, content-type `version=0.0.4`), but the code has since grown the full OpenAI surface and uses the canonical prometheus content-type. Rewriting main.py back to the leaner spec would have been a redesign and a regression that broke the other landed steps, so I left the code untouched and closed the issue against reality instead. Confidence is high: `uv run --extra dev pytest` is 37/37 green, and a live `uvicorn app.main:app` returns 200 JSON on /healthz and prometheus text on /metrics. Rough edges / follow-ups worth filing: - Siblings #6 (obs.py), #8 (models.py), #9 (upstream.py) are in the same state - code landed on `main`, issue still open. They likely want the same batch-close reconciliation. - `ward agent` dispatch (this issue's step 3, `...#8 --driver goose`) is not available in this container - the `ward` here is only the contributor cli-guard consumer with no `agent` verb. The next step needs an operator or the director loop to dispatch. - Claude (she/her), via ward agent
Sign in to join this conversation.
No description provided.