diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 38df16551..f2b01041f 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -372,7 +372,6 @@ if not DJANGO_ADMIN_ENABLED: # Middleware MIDDLEWARE = [ "strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware", - 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', @@ -386,8 +385,14 @@ MIDDLEWARE = [ 'netbox.middleware.RemoteUserMiddleware', 'netbox.middleware.CoreMiddleware', 'netbox.middleware.MaintenanceModeMiddleware', - 'django_prometheus.middleware.PrometheusAfterMiddleware', ] +if METRICS_ENABLED: + # If metrics are enabled, add the before & after Prometheus middleware + MIDDLEWARE = [ + 'django_prometheus.middleware.PrometheusBeforeMiddleware', + *MIDDLEWARE, + 'django_prometheus.middleware.PrometheusAfterMiddleware', + ] # URLs ROOT_URLCONF = 'netbox.urls'