在没有 Rollbar Heroku 附加组件的 Heroku 应用程序中添加 Rollbar

Adding Rollbar in a Heroku application without the Rollbar Heroku add-on

我正在尝试将 rollbar 添加到我在 Heroku 中的 python flask 应用程序。

Pipfile

Rollbar = "~=0.14.7"

app.py

import rollbar

rollbar_api_key = os.environ['ROLLBAR_API_KEY']

rollbar.init(rollbar_api_key)
rollbar.report_message('Rollbar is configured correctly')

try:
  b = a + 1
except:
  rollbar.report_exc_info()

但这不起作用。

我无法在 Heroku 中添加 rollbar 作为插件,因为需要提供信用卡详细信息。是否可以在没有附加组件的情况下在 heroku 中添加滚动条?

更新:

错误:

app[web.1]: import rollbar
app[web.1]: ModuleNotFoundError: No module named 'rollbar'

Link 到我要为其添加 Rollbar:

的应用程序

https://github.com/glassechidna/fwdform2

您是否设置了 ROLLBAR_API_KEY 环境变量的值?当你添加 Rollbar 附加组件时,它会为你设置,但如果你想在不使用附加组件的情况下使用 Roller,则需要自己进行设置。这可以通过 heroku config:set ROLLBAR_API_KEY=ABC123.

来完成

由于您看到错误 ModuleNotFound,似乎 rollbar python 软件包未安装。

要向项目的 PipfilePipfile.lock 添加新包,您必须使用 pipenv 包:

$ pip install pipenv 
 [...]
$ pipenv install rollbar 

Creating a Pipfile for this project…
Installing rollbar…
Adding rollbar to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (0834c3)!

With pipenv you'll need the `pipenv install` command: 
, following for example the [pipenv guide here](https://realpython.com/pipenv-guide/#example-usage). 

正如您在输出中看到的,该命令将同时更新 PipfilePipfile.lock