Django 1.5.5 アプリケーションを監視するために Sentry(6.3.2)/Raven(3.5.1) をインストールしました。ただし、False に設定すると、Sentry にエラー メッセージが届かなくなります。私のRavenアプリケーションは、「python manage.py raven test」でテストすると確実に動作します(Djangoをデバッグモードで実行したときに表示されるエラーメッセージに加えて)。Sentry は私の Django アプリケーションとは異なる仮想環境で実行され、どちらも Nginx リバース プロキシを介して実行されます。私はpython 2.6を実行しています。
私のsettings.pyは次のようになります:
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'my_db', # Or path to database file if using sqlite3.
'USER': 'my_db_user', # Not used with sqlite3.
'PASSWORD': 'my_db_pw', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "my_mail@my_provider.com"
EMAIL_HOST_PASSWORD = "my_password"
EMAIL_PORT = 25
EMAIL_USE_TLS = True
ALLOWED_HOSTS = ['my_domain', 'localhost']
TIME_ZONE = 'Europe/Zurich'
LANGUAGE_CODE = 'de-ch'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_THOUSAND_SEPARATOR = True
FORMAT_MODULE_PATH = 'my_app.formats'
MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = '/path/to/static'
STATIC_URL = 'http://myip/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
SECRET_KEY = 'my_secret_key'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages")
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
ROOT_URLCONF = 'my_app.urls'
WSGI_APPLICATION = 'my_app.wsgi.application'
TEMPLATE_DIRS = (
'/paht/to/templates',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'django_extensions',
'south',
'django.contrib.admin',
'raven.contrib.django.raven_compat',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}
RAVEN_CONFIG = {
'dsn': 'http://some_code@www.my_domain.com/sentry/2',
}
そして私の sentry.conf.py は次のようになります:
from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_sentry_db',
'USER': 'my_sentry_db_user',
'PASSWORD': 'my_sentry_db_pw',
'HOST': 'localhost',
'PORT': '',
}
}
SENTRY_URL_PREFIX = '/sentry'
FORCE_SCRIPT_NAME = '/sentry'
ALLOWED_HOSTS = ['www.my_domain.com', 'localhost', '127.0.0.1:9002']
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SENTRY_WEB_HOST = '0.0.0.0'
SENTRY_WEB_PORT = 9002
SENTRY_WEB_OPTIONS = {
'workers': 3, # the number of gunicorn workers
'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},
}
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = False
SERVER_EMAIL = 'root@sentry'
SECRET_KEY = 'my_secret_key'
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''
FACEBOOK_APP_ID = ''
FACEBOOK_API_SECRET = ''
GOOGLE_OAUTH2_CLIENT_ID = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''
GITHUB_APP_ID = ''
GITHUB_API_SECRET = ''
TRELLO_API_KEY = ''
TRELLO_API_SECRET = ''
BITBUCKET_CONSUMER_KEY = ''
BITBUCKET_CONSUMER_SECRET = ''
Django でデバッグ モードでないときに Raven/Sentry を実行するにはどうすればよいですか?
ご協力いただきありがとうございます。
更新:デバッグモードがオフの場合でも、Sentry で"SuspiciousOperation: Invalid HTTP _ HOST header (you may need to set ALLOWED _ HOSTS) " エラーメッセージが表示さ れることを追加したかっただけです。
これらのメッセージの大部分は、ALLOWED_HOSTS リストから以前のドメインの 1 つを削除したにもかかわらず、ボットがまだそのドメインを探しているという事実から来ています。
明確にするために、非デバッグモードで受信していないメッセージは、コードに「assert False」を入れるか、ランダムな文字列を入力してエラーをスローするメッセージです。