Files
mtusi2026lab2/openspec/changes/add-lab6-telemetry-pipeline/tasks.md
T
ArtyomandClaude Opus 5.5 a8836ce8b5 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>
2026-10-29 04:45:26 +03:00

39 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 1. Зависимости и платформа телеметрии
- [x] 1.1 Зависимости `opentelemetry-sdk`, `opentelemetry-exporter-otlp-proto-http`, `opentelemetry-instrumentation-fastapi`, `opentelemetry-instrumentation-asyncpg`, `faststream[rabbit,otel]` в `pyproject.toml` и `uv.lock`
- [x] 1.2 `PlatformSettings`: `otel_sdk_disabled`, `otel_exporter_otlp_endpoint`, `otel_service_name`, `telemetry_shutdown_seconds`
- [x] 1.3 `shared/infrastructure/telemetry.py`: resource, sampler `ParentBased(ServerRoots)`, batch-экспорт трёх сигналов, View без метрик FastStream, `OtlpLogHandler`, инструментация asyncpg, ограниченный `shutdown`, `tag_request`
- [x] 1.4 Журнал: `trace_id`/`span_id` в записи и в `PLATFORM_FIELDS`; `EventBus` выполняет отложенных подписчиков в контексте события
- [x] 1.5 Проверка группы: unit-тесты — выключенный SDK не ставит провайдеры, запись с span несёт `trace_id`/`span_id`, OTLP-запись содержит только allowlist, подписчик получает контекст события
## 2. Зона `attachments`
- [x] 2.1 Порт `JobObserver`, адаптер `OtelJobObserver` (counter, histogram с buckets, атрибуты и статус span), провайдер в `WorkerProvider`
- [x] 2.2 Точка входа worker: длительность, исход, `job.processed` в журнал
- [x] 2.3 Проверка группы: тест адаптера на `InMemoryMetricReader` и `InMemorySpanExporter` — labels `job.type`/`outcome`, атрибуты и `ERROR` для `failed`
## 3. Сборка процессов
- [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. Стек наблюдаемости
- [ ] 4.1 `infra/otel/collector.yaml`, `infra/prometheus/prometheus.yml` и recording rules, `infra/loki/loki.yaml`, `infra/tempo/tempo.yaml` из `.prep/lab6`
- [ ] 4.2 `infra/grafana/provisioning`, dashboards `messenger-api` и `messenger-pipeline` уровня «3»
- [ ] 4.3 `compose.yaml`: `healthtools`, `otel-collector`, `prometheus`, `loki`, `tempo`, `grafana`, volumes, секрет Grafana, сети `backend`/`edge`, переменные OTel у `api`, `relay`, `worker`; `.env.example`
- [ ] 4.4 `scripts/secrets-lab6.sh`, `scripts/obs-validate.sh`, `scripts/obs_check.py`; цели `secrets`, `obs-validate`, `telemetry-check`, `obs-evidence`
- [ ] 4.5 Проверка группы: `make obs-validate`, `docker compose config --quiet`, `make up` из чистого состояния — все сервисы `healthy`, порты наблюдаемости только на `127.0.0.1`
## 5. Проверка на стенде
- [ ] 5.1 `make test`, `make test-persistence ACTION_SCRIPT=scripts/restart.sh`, `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` для обеих реплик с `make restore`, `make level3`
- [ ] 5.2 `obs_check.py grafana`, `dashboards --strict`, `request`, `job`, `leaks`, cardinality, история после рестарта хранилищ, `make test` при остановленном Collector
- [ ] 5.3 Проверка группы: `make check`, `make validate`, `make lint`, `make student-test`
## 6. Отчёт
- [ ] 6.1 `evidence/`: стенд, smoke, persistence, failover, level3, obs-validate, grafana, dashboards, trace-request, trace-job, leaks, cardinality, telemetry-restart, student-tests, contract-checks
- [ ] 6.2 `REPORT.md`: шапка, запуск из чистого clone, архитектура и решения, роли, назначение хранилищ, соответствие сигналов и переменных, строки уровня «3», таблица отказов уровня «3»