Instrument the API, the relay and the worker

Start the telemetry in create_app, which gunicorn runs in every worker
after fork because preload_app is off, and in the relay and worker
processes with their own service names, and stop it after the rest of
the shutdown within TELEMETRY_SHUTDOWN_SECONDS. The API gets server
spans and the http.server.request.duration histogram in seconds from
the FastAPI instrumentation with stable HTTP semantic conventions,
without /health probes and without the internal send and receive
spans, and the request pipeline puts X-Request-Id on the server span
as messenger.request_id. The worker broker gets the FastStream
RabbitTelemetryMiddleware, so every delivery runs inside a consumer
span.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 04:45:26 +03:00
co-authored by Claude Opus 5.5
parent e2ec3fe9af
commit a8836ce8b5
7 changed files with 113 additions and 5 deletions
@@ -14,9 +14,9 @@
## 3. Сборка процессов
- [ ] 3.1 `main.py`: телеметрия в `create_app`, FastAPI-инструментация без `/health/*` и внутренних spans, `messenger.request_id` из конвейера, остановка в lifespan
- [ ] 3.2 `worker.py`: телеметрия `messenger-worker`, `RabbitTelemetryMiddleware` на брокере, остановка после FastStream; `relay.py`: телеметрия `messenger-relay`
- [ ] 3.3 Проверка группы: тест server span и HTTP-метрики на `create_app` с in-memory провайдерами — шаблон маршрута, без `/health`, `messenger.request_id`; `make lint`, `make student-test`
- [x] 3.1 `main.py`: телеметрия в `create_app`, FastAPI-инструментация без `/health/*` и внутренних spans, `messenger.request_id` из конвейера, остановка в lifespan
- [x] 3.2 `worker.py`: телеметрия `messenger-worker`, `RabbitTelemetryMiddleware` на брокере, остановка после FastStream; `relay.py`: телеметрия `messenger-relay`
- [x] 3.3 Проверка группы: тест server span и HTTP-метрики на `create_app` с in-memory провайдерами — шаблон маршрута, без `/health`, `messenger.request_id`; `make lint`, `make student-test`
## 4. Стек наблюдаемости