From c481519c68a6ac722a9ecca03bdb09d689af83c8 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Wed, 4 Oct 2023 10:21:08 +0200 Subject: [PATCH] Fix: Errors in guest_api were not reported on Sentry --- guest_api/__main__.py | 25 ++++++++++++++++++++-- vm_supervisor/__main__.py | 2 +- vm_supervisor/vm/firecracker/executable.py | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/guest_api/__main__.py b/guest_api/__main__.py index 829680bbf..1692139a3 100644 --- a/guest_api/__main__.py +++ b/guest_api/__main__.py @@ -4,10 +4,15 @@ from typing import Optional import aiohttp -from aiohttp import web import aioredis +from aiohttp import web from setproctitle import setproctitle +try: + import sentry_sdk +except ImportError: + sentry_sdk = None + logger = logging.getLogger(__name__) ALEPH_API_SERVER = "https://official.aleph.cloud" @@ -155,7 +160,23 @@ async def list_keys_from_cache(request: web.Request): return web.json_response(keys) -def run_guest_api(unix_socket_path, vm_hash: Optional[str] = None): +def run_guest_api( + unix_socket_path, + vm_hash: Optional[str] = None, + sentry_dsn: Optional[str] = None, + server_name: Optional[str] = None, +): + # This function runs in a separate process, requiring to reinitialize the Sentry SDK + if sentry_sdk and sentry_dsn: + sentry_sdk.init( + dsn=sentry_dsn, + server_name=server_name, + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + # We recommend adjusting this value in production. + traces_sample_rate=1.0, + ) + setproctitle(f"aleph-vm guest_api on {unix_socket_path}") app = web.Application() app["meta_vm_hash"] = vm_hash or "_" diff --git a/vm_supervisor/__main__.py b/vm_supervisor/__main__.py index 2f78d9471..5342ebeac 100644 --- a/vm_supervisor/__main__.py +++ b/vm_supervisor/__main__.py @@ -324,7 +324,7 @@ def main(): traces_sample_rate=1.0, ) else: - logger.debug("Sentry SDK found with no DNS configured.") + logger.debug("Sentry SDK found with no DSN configured.") else: logger.debug( "Sentry SDK not found. \n" diff --git a/vm_supervisor/vm/firecracker/executable.py b/vm_supervisor/vm/firecracker/executable.py index 0d3985d53..3bad89bd5 100644 --- a/vm_supervisor/vm/firecracker/executable.py +++ b/vm_supervisor/vm/firecracker/executable.py @@ -269,7 +269,8 @@ async def start_guest_api(self): vsock_path = f"{self.fvm.vsock_path}_53" vm_hash = self.vm_hash self.guest_api_process = Process( - target=run_guest_api, args=(vsock_path, vm_hash) + target=run_guest_api, + args=(vsock_path, vm_hash, settings.SENTRY_DSN, settings.DOMAIN_NAME), ) self.guest_api_process.start() while not exists(vsock_path):