为哨兵设置 Apache2 mod_wsgi

Setup Apache2 mod_wsgi for sentry

我已经使用了通过以下 apache 配置安装在 virtualenv 上的 sentry 8.1:

<VirtualHost x.x.x.x:80>
        WSGIDaemonProcess sentry python-path=/var/www/sentry-me:/var/www/sentry-me/env/lib/python2.7/site-packages
        WSGIProcessGroup sentry
        WSGIScriptAlias / /var/www/sentry-me/env/lib/python2.7/site-packages/sentry/wsgi.py
</VirtualHost>

一切正常,但在我将 sentry 更新到 8.3.3 后,静态文件出现问题,在 apache 日志中我看到以下异常:

[Sun May 01 16:38:46.106931 2016] [wsgi:error] [pid 19046] [remote 5.39.50.57:27319] Traceback (most recent call last):
[Sun May 01 16:38:46.106960 2016] [wsgi:error] [pid 19046] [remote 5.39.50.57:27319]   File "/var/www/sentry-me/env/lib/python2.7/site-packages/raven/middleware.py", line 48, in __call__
[Sun May 01 16:38:46.107006 2016] [wsgi:error] [pid 19046] [remote 5.39.50.57:27319]     for event in iterable:
[Sun May 01 16:38:46.107043 2016] [wsgi:error] [pid 19046] [remote 5.39.50.57:27319] KeyError: 'file like object has no read() method'

iterable 的类型是 FileWrapper,我的 sentry virtualenv 中目前还安装了以下软件包:

amqp==1.4.9
anyjson==0.3.3
BeautifulSoup==3.2.1
billiard==3.3.0.23
celery==3.1.18
cffi==1.6.0
click==6.6
contextlib2==0.5.1
cryptography==1.3.1
cssselect==0.9.1
cssutils==0.9.10
Django==1.6.11
django-bitfield==1.7.1
django-crispy-forms==1.4.0
django-debug-toolbar==1.3.2
django-jsonfield==0.9.13
django-paging==0.2.5
django-picklefield==0.3.2
django-recaptcha==1.0.5
django-social-auth==0.7.28
django-sudo==1.2.1
django-templatetag-sugar==1.0
djangorestframework==2.3.14
email-reply-parser==0.2.0
enum34==1.1.4
exam==0.10.5
hiredis==0.1.6
httplib2==0.9.2
idna==2.1
ipaddr==2.1.11
ipaddress==1.0.16
kombu==3.0.30
lxml==3.6.0
mock==1.0.1
ndg-httpsclient==0.4.0
oauth2==1.9.0.post1
petname==1.7
progressbar==2.3
psycopg2==2.6.1
py==1.4.31
pyasn1==0.1.9
pycparser==2.14
pyOpenSSL==16.0.0
pytest==2.6.4
pytest-django==2.9.1
python-dateutil==2.5.3
python-memcached==1.57
python-openid==2.2.5
pytz==2016.4
PyYAML==3.11
raven==5.13.0
rb==1.4
redis==2.10.5
requests==2.9.2
sentry==8.3.3
setproctitle==1.1.9
simplejson==3.8.2
six==1.10.0
South==1.0.1
sqlparse==0.1.19
statsd==3.1
toronado==0.0.7
ua-parser==0.7.0
urllib3==1.14
uWSGI==2.0.12

我如下更改了 */my-venv/lib/python2.7/site-packages/sentry/wsgi.py 的最新行,现在可以正常工作了:

application = WSGIHandler()  # Sentry(FileWrapperWSGIHandler())

但我认为 sentry 无法监控和显示内部异常,在下一步中我更改了 application 变量定义行,如下所示:

application = Sentry(WSGIHandler())  # Sentry(FileWrapperWSGIHandler())

而且我认为这段代码工作正常。