Bug Fix: pyrollbar: No access_token provided.
Credentials and authentication issues preventing the rollbar agent in our backend from calling home.
1. Problem
Although the rollbar
access_token
is configured with the python variablerollbar_access_token
, the agent isn't calling home, and no data are coming through on the Rollbar side.

2. Analysis
Something must be wrong with the variable
rollbar_access_token
in line 94 (in the above image).After good dozens of minutes, I finally figured out: there are multiple
access_tokens
at varying levels in Rollbar - one at the project level (for each project) and the other at the account level.I was using the account level token where I have to input the project access token.
3. Solution
export ROLLBAR_ACCESS_TOKEN="YOUR_ROLLBAR_TOKEN_FROM_PROJECT"
gp env ROLLBAR_ACCESS_TOKEN="YOUR_ROLLBAR_TOKEN_FROM_PROJECT"

However, I still get the same error that the access_token
is not provided. Well... the error message was quite stragithforward in fact. It's been telling me to "call" the rollbar.init()
function.

Reorganise the Rollbar code.
Call
init_rollbar()
underwith app.app_context():
function (code fix here).
# ROLLBAR -------------------------
rollbar_access_token = os.getenv('ROLLBAR_ACCESS_TOKEN')
def init_rollbar():
"""init rollbar module"""
rollbar.init(
# access token
rollbar_access_token,
# environment name
'production',
# server root directory, makes tracebacks prettier
root=os.path.dirname(os.path.realpath(__file__)),
# flask already sets up logging
allow_logging_basic_config=False)
# send exceptions from `app` to rollbar, using flask's signal system.
got_request_exception.connect(rollbar.contrib.flask.report_exception, app)
# @app.before_first_request # this decorator will break the code as it is depricated after Flask 2.2
with app.app_context(): # use this 'with' statement instead.
init_rollbar()
# ROLLBAR TEST---------------------
@app.route('/rollbar/test')
def rollbar_test():
rollbar.report_message('Hello Rollbar!', 'warning')
return "Hello, Rollbar!"
4. Result
The error message
pyrollbar: No access_token provided
is gone.I check the Rollbar console and the spans are coming through.



Last updated