Добавлен сбор телеметрии на ВМ2

This commit is contained in:
mi
2026-08-26 15:12:51 +03:00
parent 728b9826a3
commit f989097484
32 changed files with 2029 additions and 134 deletions
@@ -10,12 +10,14 @@ from dataclasses import dataclass
from pathlib import Path
from typing import Protocol
from opentelemetry import trace
from PIL import Image, UnidentifiedImageError
from pillow_heif import register_heif_opener
from app.contracts import Attachment
register_heif_opener()
tracer = trace.get_tracer("message-safety.dependencies")
class ObjectChanged(RuntimeError):
@@ -122,6 +124,13 @@ class ClamAvInstream:
self.host, self.port, self.timeout = host, port, timeout
async def scan(self, chunks: AsyncIterator[bytes]) -> str | None:
with tracer.start_as_current_span(
"message_safety.clamav.scan",
attributes={"server.address.type": "clamav"},
):
return await self._scan(chunks)
async def _scan(self, chunks: AsyncIterator[bytes]) -> str | None:
async def operation() -> str | None:
reader, writer = await asyncio.open_connection(self.host, self.port)
try:
@@ -148,6 +157,10 @@ class ClamAvInstream:
raise DependencyFailure("ClamAV unavailable") from exc
async def signatures_version(self) -> str:
with tracer.start_as_current_span("message_safety.clamav.version"):
return await self._signatures_version()
async def _signatures_version(self) -> str:
try:
reader, writer = await asyncio.wait_for(
asyncio.open_connection(self.host, self.port), 2.0