diff --git a/onlineweb4/settings/django.py b/onlineweb4/settings/django.py index 04e229f1a..67984d7ac 100644 --- a/onlineweb4/settings/django.py +++ b/onlineweb4/settings/django.py @@ -145,6 +145,8 @@ "django.contrib.messages.middleware.MessageMiddleware", "reversion.middleware.RevisionMiddleware", "mozilla_django_oidc.middleware.SessionRefresh", + # add user id + "onlineweb4.settings.sentry.sentry_middleware", # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] @@ -201,7 +203,6 @@ "apps.approval", "apps.article", "apps.authentication", - "apps.autoconfig", "apps.careeropportunity", "apps.companyprofile", "apps.contact", diff --git a/onlineweb4/settings/sentry.py b/onlineweb4/settings/sentry.py index bd4505345..88902e34d 100644 --- a/onlineweb4/settings/sentry.py +++ b/onlineweb4/settings/sentry.py @@ -10,7 +10,27 @@ sentry_sdk.init( dsn=OW4_SENTRY_DSN, environment=config("OW4_ENVIRONMENT", default="DEVELOP"), - traces_sample_rate=0.2, + enable_tracing=True, + profiles_sample_rate=0.2, integrations=[DjangoIntegration(), AwsLambdaIntegration(timeout_warning=True)], ignore_errors=[ValidationError], ) + + +def sentry_middleware(get_response): + # One-time configuration and initialization. + + def middleware(request): + # Code to be executed for each request before + # the view (and later middleware) are called. + sentry_sdk.set_user( + None if request.user.is_anonymous else {"id": request.user.pk} + ) + response = get_response(request) + + # Code to be executed for each request/response after + # the view is called. + + return response + + return middleware