Реализовать observability для лабораторной 6

This commit is contained in:
2026-11-20 17:55:23 +03:00
parent 58f3d4c457
commit 9e6428de05
50 changed files with 3573 additions and 98 deletions
+20 -2
View File
@@ -20,6 +20,8 @@ from ..domain.errors import (
UnsupportedMediaType,
)
from ..domain.models import Attachment, User
from ..observability.logging import safe_extra
from ..observability.propagation import inject_trace_context
from ..repositories import AttachmentRepository
from ..storage import ObjectStream, S3Storage
@@ -112,8 +114,9 @@ class AttachmentService:
staging_key = f'staging/{attachment_id}/original'
await self._storage.put(staging_key, source, size, actual_type)
now = datetime.now(timezone.utc)
trace_context = inject_trace_context()
try:
return await self._repository.create_queued(
attachment = await self._repository.create_queued(
attachment_id=attachment_id,
job_id=job_id,
chat_id=chat_id,
@@ -127,12 +130,27 @@ class AttachmentService:
height=height,
max_attempts=self._job_max_attempts,
now=now,
traceparent=trace_context.get('traceparent'),
tracestate=trace_context.get('tracestate'),
)
logger.info(
'attachment accepted for asynchronous processing',
extra=safe_extra(
'attachment.accepted', attachment_id=str(attachment_id),
job_id=str(job_id), pipeline_version=1,
),
)
return attachment
except Exception:
try:
await self._storage.remove(staging_key)
except Unavailable:
logger.warning('failed to compensate staging object key=%s', staging_key)
logger.warning(
'failed to compensate staging object',
extra=safe_extra(
'staging.cleanup_deferred', attachment_id=str(attachment_id)
),
)
raise
async def get(self, actor: User, attachment_id: UUID) -> Attachment: