1

I wanted to monitor my django app with prometheus and I added the django-prometheus(2.1.0) and then all my requests, except /metrics causes 500 when DEBUG=FALSE. I can't understand why it's only working with DEBUG=TRUE.

    # 'django_prometheus.middleware.PrometheusBeforeMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # 'django_prometheus.middleware.PrometheusAfterMiddleware',

Is there anything wrong with my middlewares?

----- Update: The only other thing which I've done when DEBUG=FALSE is:

if not DEBUG:
    sentry_sdk.init(
        "<sentry_url>",
        integrations=[DjangoIntegration()]
    )

I also have used django_prometheus.models.ExportModelOperationsMixin for my models.

related requirements version:

   sentry-sdk==0.14.3
   django-prometheus==2.1.0
no746
  • 408
  • 6
  • 23

1 Answers1

1

The problem is not because of django-prometheus middleware. It's actually because of sentry-sdk version. This is the related issue. This issue was fixed in 0.16 version of sentry-sdk, so I updated the sentry-sdk version and it was resolved.

no746
  • 408
  • 6
  • 23