Реализовать уровень 4: сквозные трассы, SLO, отказы и отчёт

This commit is contained in:
2026-11-21 12:18:33 +03:00
parent d0a062e2d2
commit 12181fa893
69 changed files with 52258 additions and 47 deletions
+12 -4
View File
@@ -9,6 +9,7 @@ from uuid import UUID, uuid4
from sqlalchemy import text
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from app.trace_context import carrier
async def create_user(
@@ -580,14 +581,17 @@ async def finalize_attachment(
job_id = uuid4()
final_key = f"originals/{attachment_id}/v1/original"
context = carrier()
result = await db.execute(
text(
f"""
INSERT INTO attachments AS a
(id, chat_id, owner_id, filename, content_type, size_bytes,
sha256, width, height, object_key, staging_key, job_id, status)
sha256, width, height, object_key, staging_key, job_id, status,
traceparent, tracestate)
VALUES (:id, :chat_id, :owner_id, :filename, :content_type,
:size_bytes, :sha256, :width, :height, :final_key, :object_key, :job_id, 'queued')
:size_bytes, :sha256, :width, :height, :final_key, :object_key, :job_id, 'queued',
:traceparent, :tracestate)
RETURNING {ATTACHMENT_COLUMNS}
"""
),
@@ -604,12 +608,16 @@ async def finalize_attachment(
"object_key": object_key,
"final_key": final_key,
"job_id": job_id,
"traceparent": context.get("traceparent"),
"tracestate": context.get("tracestate"),
},
)
row = dict(result.mappings().one())
await db.execute(
text("INSERT INTO outbox (job_id, attachment_id, attempt) VALUES (:job_id, :id, 1)"),
{"job_id": job_id, "id": attachment_id},
text("""INSERT INTO outbox (job_id, attachment_id, attempt, traceparent, tracestate)
VALUES (:job_id, :id, 1, :traceparent, :tracestate)"""),
{"job_id": job_id, "id": attachment_id,
"traceparent": context.get("traceparent"), "tracestate": context.get("tracestate")},
)
await db.commit()
return row