From e06bdab15198eee785b9d77cf015fc7bf8c16001 Mon Sep 17 00:00:00 2001 From: delcroip Date: Thu, 14 Nov 2024 14:16:40 +0100 Subject: [PATCH 1/2] remove duplicated config --- openIMIS/openIMIS/settings/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openIMIS/openIMIS/settings/base.py b/openIMIS/openIMIS/settings/base.py index 089320c..2ff09f4 100644 --- a/openIMIS/openIMIS/settings/base.py +++ b/openIMIS/openIMIS/settings/base.py @@ -192,4 +192,3 @@ def SITE_URL(): # By default, the maximum upload size is 2.5Mb, which is a bit short for base64 picture upload DATA_UPLOAD_MAX_MEMORY_SIZE = int(os.environ.get('DATA_UPLOAD_MAX_MEMORY_SIZE', 10 * 1024 * 1024)) -FRONTEND_URL = os.environ.get("FRONTEND_URL", "") From 85a7712bb26df89d0b545a38195030ea571894cb Mon Sep 17 00:00:00 2001 From: delcroip Date: Mon, 18 Nov 2024 21:44:39 +0100 Subject: [PATCH 2/2] add sentry std middelware --- openIMIS/a.out | 0 openIMIS/openIMIS/settings/base.py | 1 + openIMIS/openIMIS/tracer.py | 14 +++----------- 3 files changed, 4 insertions(+), 11 deletions(-) create mode 100644 openIMIS/a.out diff --git a/openIMIS/a.out b/openIMIS/a.out new file mode 100644 index 0000000..e69de29 diff --git a/openIMIS/openIMIS/settings/base.py b/openIMIS/openIMIS/settings/base.py index 2ff09f4..80137f3 100644 --- a/openIMIS/openIMIS/settings/base.py +++ b/openIMIS/openIMIS/settings/base.py @@ -105,6 +105,7 @@ def SITE_URL(): } MIDDLEWARE = [ + 'sentry_sdk.integrations.django.middleware.SentryMiddleware' "django.middleware.security.SecurityMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", 'core.middleware.GraphQLRateLimitMiddleware', diff --git a/openIMIS/openIMIS/tracer.py b/openIMIS/openIMIS/tracer.py index c274fd0..e3862bb 100644 --- a/openIMIS/openIMIS/tracer.py +++ b/openIMIS/openIMIS/tracer.py @@ -2,6 +2,7 @@ from contextlib import contextmanager from .settings import IS_SENTRY_ENABLED, DEBUG import traceback +from graphql import GraphQLError logger = logging.getLogger(__name__) @@ -38,14 +39,5 @@ def resolve(self, next, root, info, **kwargs): # Proceed with the next middleware or resolver return next(root, info, **kwargs) except Exception as e: - # Log the exception with its traceback - if DEBUG: - logger.error("An error occurred: %s", str(e)) - logger.error("Traceback: %s", traceback.format_exc()) - - # Optionally add error information to the trace - span.set_tag("error", True) - span.log_kv({"exception": str(e), "traceback": traceback.format_exc()}) - - # Re-raise the exception to allow GraphQL to handle it - raise e \ No newline at end of file + sentry_sdk.capture_exception(e) + raise GraphQLError(str(e)) \ No newline at end of file