Skip to content

Commit

Permalink
Install prometheus to collect Django metrics (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmadMokhtar authored Jan 1, 2023
1 parent 91d6d61 commit f4c3819
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ django-cors-headers==3.7.0
pytz==2017.2
django-environ==0.4.4
django-filter==2.4.0
rollbar==0.14.5
django-prometheus==2.2.0
psycopg2==2.8.5
sentry-sdk==1.12.1
1 change: 0 additions & 1 deletion requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Pygments==2.13.0
python-dateutil==2.6.1
pytz==2017.2
requests==2.20.1
rollbar==0.14.5
sentry-sdk==1.12.1
six==1.11.0
sqlparse==0.2.4
Expand Down
39 changes: 21 additions & 18 deletions tafseer_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
environ.Env.read_env(env_file_path) # reading .env file

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env('DEBUG')
DEBUG = env.bool('DEBUG')

SECRET_KEY = env('SECRET_KEY')

Expand All @@ -29,6 +29,7 @@
# 3rd party Apps
'rest_framework',
'corsheaders',
'django_prometheus',
# Internal Apps
'quran_text',
'quran_tafseer',
Expand All @@ -40,6 +41,7 @@
POST_MIDDLEWARE = env.list('POST_MIDDLEWARE', default=[])

MIDDLEWARE = PRE_MIDDLEWARE + [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
Expand All @@ -49,7 +51,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'rollbar.contrib.django.middleware.RollbarNotifierMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
] + POST_MIDDLEWARE

ROOT_URLCONF = 'tafseer_api.urls'
Expand Down Expand Up @@ -136,19 +138,20 @@

# Sentry

sentry_dsn = env('SENTRY_DSN')
sentry_sdk.init(
dsn=sentry_dsn,
integrations=[
DjangoIntegration(),
],

# 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,

# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True
)
sentry_dsn = env.str('SENTRY_DSN', None)
if sentry_dsn is None:
sentry_sdk.init(
dsn=sentry_dsn,
integrations=[
DjangoIntegration(),
],

# 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,

# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True
)
1 change: 1 addition & 0 deletions tafseer_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def trigger_error(request):
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
url('sentry-debug/', trigger_error),
url('', include('django_prometheus.urls')),
]

urlpatterns += i18n_patterns(url(r'^', include('docs.urls')))

0 comments on commit f4c3819

Please sign in to comment.