# Доказывает (уровни 3–4): стек наблюдаемости работает на рабочем стенде —
#   Grafana с тремя источниками и dashboard (26 панелей); у контрольного
#   запроса одна трасса в Tempo, запись в Loki и строка stdout с тем же
#   trace_id; трасса загрузки доходит до worker (consumer span, outcome ready);
#   метрики API, worker, relay, resource attributes; метки без id, URL и имён
#   файлов; в телеметрии нет пароля, токена, текста сообщения, filename.
# Дата: 2026-11-15, 22:21 UTC.
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9.
# Стенд: рабочий (make up); LB 127.0.0.1:8180, Grafana 127.0.0.1:3180.
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
# Повторить: make up && make telemetry-check

$ make telemetry-check
python3 scripts/lab6.py telemetry-check --base-url "http://localhost:8180"
PASS  grafana /api/health: status 200
PASS  datasources provisioned: ['logs', 'metrics', 'traces']
PASS  dashboard messenger-lab6 provisioned: status 200, panels 26
PASS  controlled request GET /api/v1/users/me: status 200, X-Request-Id tcheck-7eaa7b98-me
PASS  upload accepted: status 202
PASS  attachment ready: ready
PASS  message with attachment: status 201
PASS  API trace found by request id: 60e5d0f213673aa90c8f6f69e4dcd077
PASS  server span with route template: 2 spans: GET /api/v1/users/me, postgresql read
PASS  no spans from FastAPI native telemetry: []
PASS  API log record in Loki with the same trace_id: GET /api/v1/users/me -> 200 (1.2 ms)
PASS  API stdout line carries the same trace_id: 2026-11-15T22:21:42.677Z INFO    src.http [rid=tcheck-7eaa7b98-me] GET /api/v1/users/me -> 200 (1.2 ms) trace_id=60e5d0f2...
PASS  upload trace has PostgreSQL and S3 child spans: POST /api/v1/chats/{chat_id}/attachments, S3 get_object, S3 put_object, postgresql read, postgresql transaction, process messenger.attachment-jobs
PASS  worker consumer span with outcome ready: ... process messenger.attachment-jobs, publi...
PASS  worker log 'attachment processed' with the job trace_id: attachment processed attachment_id=b28e18e8-... job_id=a1b6e40c-... trace_id=...
PASS  HTTP duration histogram (API): count 3
PASS  job duration histogram (worker, ready): count 2
PASS  relay published counter: 2
PASS  resource attributes (target_info): messenger-api@0.6.0/lab, messenger-relay@0.6.0/lab, messenger-worker@0.6.0/lab
PASS  HTTP histogram has a single source: rate 0
PASS  metric labels without ids, raw URLs and filenames: 35 series
PASS  no password, token, message text, filename or Authorization in telemetry: 84 log records, 63821 bytes of traces
telemetry-check: PASS (22/22 checks)

# Итог: 22/22. Пара «трасса — запись журнала» у контрольного запроса:
# trace_id 60e5d0f2… в Tempo, в Loki и в stdout API (1 пара запрос → трасса →
# лог); у загрузки — трасса с PostgreSQL, S3 и consumer span worker и строка
# worker `attachment processed` с trace_id задания (вторая пара). Утечек
# секретов и текстов в 84 записях журнала и 63 821 байте трасс нет.
