Подключить OpenTelemetry, Collector и Grafana для оценки 5.

API и worker отдают метрики, логи и трассы. Правила SLO записаны, прогон инцидентов ещё впереди.
This commit is contained in:
2026-11-17 15:23:33 +03:00
parent 14ab803529
commit baee48072c
26 changed files with 1279 additions and 113 deletions
+27 -13
View File
@@ -8,7 +8,7 @@ import logging
import aio_pika
from app import config
from app import config, telemetry
logger = logging.getLogger("messenger.broker")
@@ -49,19 +49,33 @@ async def _ensure() -> tuple[aio_pika.RobustChannel, aio_pika.Exchange]:
return _channel, _exchange
async def publish_job(payload: dict) -> None:
async def publish_job(payload: dict, traceparent: str | None = None, tracestate: str | None = None) -> None:
channel, exchange = await _ensure()
body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
await exchange.publish(
aio_pika.Message(
body=body,
content_type="application/json",
delivery_mode=aio_pika.DeliveryMode.PERSISTENT,
message_id=payload["job_id"],
),
routing_key=ROUTING_KEY,
mandatory=True,
)
parent = telemetry.remote_context(traceparent, tracestate)
with telemetry.span(
"attachment.job.publish",
context=parent,
kind="producer",
attributes={
"messaging.system": "rabbitmq",
"messaging.destination.name": QUEUE,
"messaging.operation": "publish",
"job.id": payload.get("job_id"),
},
):
headers = telemetry.current_carrier() or None
body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
await exchange.publish(
aio_pika.Message(
body=body,
content_type="application/json",
delivery_mode=aio_pika.DeliveryMode.PERSISTENT,
message_id=payload["job_id"],
headers=headers,
),
routing_key=ROUTING_KEY,
mandatory=True,
)
async def publish_delay(payload: dict, delay_seconds: float) -> None: