【问题标题】:Adding a hook to Gunicorn for raven-python (sentry client)为 raven-python(哨兵客户端)添加 Gunicorn 的钩子
【发布时间】:2013-01-09 11:27:08
【问题描述】:

我想知道我将把它放在我的代码或 gunicorn 的什么地方,以便让 raven 运行。 http://raven.readthedocs.org/en/latest/config/django.html#gunicorn

【问题讨论】:

    标签: python gunicorn sentry raven


    【解决方案1】:

    有点晚了,但无论如何:)

    您需要将此添加到您的 Gunicorn 配置文件中。例如,当您启动 gunicorn_django 时,您可以传递一个 -c (--config) 参数,该参数采用 python 文件的路径。

    Gunicorn 将使用此文件加载未作为参数传递的配置设置,如工作程序和日志路径等。但您也可以包含 gunicorn 将在进程生命周期的某些点调用的函数。根据 Raven 文档,这是放置 raven 设置的地方。

    例如:

    $ gunicorn_django -c /path/to/gunicorn_settings.py
    

    该文件可能包含以下内容:

    workers = 2
    bind = 'unix:/tmp/my_project_name.sock'  # Binds to a unix socket rather than ip/port
    errorlog = '/path/to/logs/gunicorn.error.log'
    
    def when_ready(server):
        from django.core.management import call_command
        call_command('validate')
    

    注意确保您的DJANGO_SETTINGS_MODULE 正确导出,否则call_command('validate') 将抛出SystemExit 并且您的进程将无法启动。

    您可以阅读更多关于 Gunicorn 配置文件的信息:http://docs.gunicorn.org/en/latest/configure.html

    【讨论】:

    • 真的需要这个了吗?我知道 raven 文档建议添加这个钩子,但我不明白为什么它是必要的。即使我没有添加这个钩子,我也没有任何问题。有一张关于这个github.com/getsentry/raven-python/issues/286的github票
    • call_command('validate') 正在抛出 SystemExit,如何正确导出 DJANGO_SETTINGS_MODULE? @krak3n
    • 您需要将其导出为环境变量。运行 Gunicorn 时尝试运行: gunicorn -b 127.0.0.1:8000 --env DJANGO_SETTINGS_MODULE=path.to.settings 您还可以在 gunicorn 配置文件中设置环境变量。
    • gunicorn salon.wsgi -c salon/gunicorn.conf.py --env DJANGO_SETTINGS_MODULE=salon.settings ,但返回:“ImportError: 无法导入设置 'salon.settings'(是否开启sys.path?设置文件中是否有导入错误?):没有名为salon.settings的模块
    • 我不知道您的应用程序设置,它会提示您可能存在什么问题,您的应用程序需要在 python 路径上,是否安装正确等?请在 python 包装上查看:scotttorborg.com/python-packaging
    猜你喜欢
    • 2018-03-22
    • 2012-08-03
    • 2018-02-03
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 2016-04-29
    • 2021-07-24
    • 1970-01-01
    相关资源
    最近更新 更多