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

371 Views Asked by At

I am trying to add rollbar to my python flask application in Heroku.

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()

But this is not working.

I am not able to add rollbar as an addon in Heroku since credit card details are required. Is it possible to add rollbar in heroku without the add-on?

Update:

Error:

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

Link to the app for which I am trying to add Rollbar:

https://github.com/glassechidna/fwdform2

2

There are 2 best solutions below

0
On BEST ANSWER

Since you are seeing the error ModuleNotFound, it seems like the rollbar python package is not installed.

To add a new package to the project's Pipfile and Pipfile.lock you have to use the pipenv package:

$ 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). 

As you see in the output the command will update both Pipfile and Pipfile.lock.

1
On

Did you set the ROLLBAR_API_KEY environment variable's value? When you add the Rollbar add-on, it sets that for you, but if you want to use Roller without using the add-on, you'll need to set that yourself. This can be done with heroku config:set ROLLBAR_API_KEY=ABC123.