Добавить наблюдаемость OpenTelemetry и Grafana на оценку 3
This commit is contained in:
+9
-1
@@ -14,6 +14,7 @@ from app.db import SessionLocal, engine
|
||||
from app.pipeline import (RETENTION_SECONDS, arm_from_env, broker_channel,
|
||||
crash_if_armed, envelope, publish, retry_or_fail)
|
||||
from app.storage import storage
|
||||
from app.telemetry import configure, emit, install_termination_handler, shutdown
|
||||
|
||||
logger = logging.getLogger("messenger.jobs")
|
||||
|
||||
@@ -86,10 +87,13 @@ async def relay_one(channel) -> bool:
|
||||
{"id": row["id"]})
|
||||
await db.commit()
|
||||
logger.info("published job=%s attempt=%s", row["job_id"], row["attempt"])
|
||||
emit("job.published", job_id=str(row["job_id"]), attempt=row["attempt"])
|
||||
return True
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
configure("messenger-publisher")
|
||||
install_termination_handler()
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
||||
for name in ("aio_pika", "aiormq"):
|
||||
logging.getLogger(name).setLevel(logging.CRITICAL)
|
||||
@@ -128,7 +132,11 @@ async def main() -> None:
|
||||
await connection.close()
|
||||
await storage.close()
|
||||
await engine.dispose()
|
||||
await asyncio.to_thread(shutdown)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except asyncio.CancelledError:
|
||||
pass # SIGTERM has run finally/SDK flush; exit cleanly.
|
||||
|
||||
Reference in New Issue
Block a user