feat: propagate trace context through outbox and add pipeline saturation metrics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 19:54:37 +03:00
co-authored by Claude Opus 5.5
parent ff0073e8e3
commit 72cfa9aaf6
64 changed files with 4699 additions and 552 deletions
+15
View File
@@ -29,6 +29,7 @@ from src.core.services import (
SessionService,
UserService,
)
from src.infra import telemetry
from src.infra.cache.instance import cache
from src.infra.db import ping
from src.infra.db.scope import deadline_scope
@@ -124,6 +125,20 @@ AttachmentServiceDep = Annotated[
]
async def get_trace_context() -> dataclasses.TraceContextDTO | None:
"""Контекст W3C текущего span — server span запроса — для задания
загрузки (design change `job-trace-propagation`, решение 4); без
телеметрии — `None`. Сервис телеметрию не импортирует: контекст приходит
значением, как `owner_id`."""
return telemetry.current_trace_context()
TraceContextDep = Annotated[
dataclasses.TraceContextDTO | None,
Depends(get_trace_context),
]
# схемы basicAuth и bearerAuth из contracts/openapi.json: объявлены в
# /openapi.json и дают кнопку Authorize в /docs. auto_error=False — нет
# заголовка или схема чужая даёт None, а 401 в формате контракта бросает
+11 -3
View File
@@ -15,7 +15,11 @@ from fastapi.responses import StreamingResponse
from starlette.background import BackgroundTask
from starlette.requests import ClientDisconnect
from src.api.dependencies import AttachmentServiceDep, CurrentUser
from src.api.dependencies import (
AttachmentServiceDep,
CurrentUser,
TraceContextDep,
)
from src.api.schemas import Attachment, DisplayFilename, UuidIn
from src.core import exceptions
from src.schemas.enums import AttachmentVariantName, ImageType
@@ -112,9 +116,12 @@ async def upload_attachment(
filename: FilenameQuery,
request: Request,
attachments: AttachmentServiceDep,
trace_context: TraceContextDep,
) -> Attachment:
"""202 — оригинал в staging, метаданные и задание в PostgreSQL, брокер
подтвердил сообщение; итог клиент узнаёт по метаданным.
"""202 — оригинал в staging, вложение `queued` и задание в PostgreSQL
одной транзакцией; сообщение публикует relay, итог клиент узнаёт по
метаданным. Контекст server span загрузки сохраняется в задании (design
change `job-trace-propagation`, решение 4).
Тело не читается, пока не пройдены вход, параметры, членство,
`Content-Type` и `Content-Length` (спек «Порядок проверок загрузки»).
@@ -129,6 +136,7 @@ async def upload_attachment(
media_type=_media_type(request),
content_length=_content_length(request),
body=_body(request),
trace_context=trace_context,
)
return Attachment.model_validate(attachment)