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
@@ -23,6 +23,7 @@ from src.config import settings
from src.core import exceptions
from src.core.services import AttachmentService
from src.infra.upload_slots import UploadSlots
from src.schemas import dataclasses
from src.schemas.enums import (
AttachmentErrorCode,
AttachmentJobState,
@@ -140,6 +141,45 @@ async def test_upload_order_and_events(
assert not database.inside_block("storage.put")
async def test_upload_saves_trace_context_in_job(
service: AttachmentService,
database: FakeDatabase,
world: tuple[UUID, UUID, UUID],
) -> None:
"""Контекст загрузки — в задании той же транзакцией, что `queued`
(design change `job-trace-propagation`, решение 4)."""
alice, _, chat_id = world
context = dataclasses.TraceContextDTO(
traceparent="00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
tracestate="vendor=value",
)
attachment = await service.upload(
chat_id=chat_id,
owner_id=alice,
filename="a.png",
media_type="image/png",
content_length=None,
body=_body(SAMPLE),
trace_context=context,
)
(job,) = database.jobs.values()
assert job.attachment_id == attachment.id
assert job.traceparent == context.traceparent
assert job.tracestate == "vendor=value"
async def test_upload_without_trace_context(
service: AttachmentService,
database: FakeDatabase,
world: tuple[UUID, UUID, UUID],
) -> None:
"""Без телеметрии контекста нет — колонки задания пусты."""
await _upload(service, world)
(job,) = database.jobs.values()
assert job.traceparent is None
assert job.tracestate is None
def _fill_backlog(database: FakeDatabase, count: int) -> None:
"""`count` незавершённых заданий: `queued` и `processing` поровну."""
for number in range(count):