Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to reinitialize rollbar #337

Open
bongolegend opened this issue May 5, 2020 · 3 comments
Open

how to reinitialize rollbar #337

bongolegend opened this issue May 5, 2020 · 3 comments

Comments

@bongolegend
Copy link

I'd like to reinitialize rollbar, to connect to a different rollbar project. Looks like this isn't currently supported, but I found a hacky solution. Is it bad to do this? Are there negative side-effects?

pyrollbar 0.14.5

In [1]: import rollbar
In [2]: rollbar.init('first')
In [3]: rollbar.init('second')
WARNING:rollbar:Rollbar already initialized. Ignoring re-init.
In [4]: rollbar._initialized
Out[4]: True
In [5]: rollbar._initialized = False
In [6]: rollbar.init('second')
@terencehonles
Copy link
Contributor

I haven't looked into this much (and this is not my library, but I have submitted a couple PRs against this repo), however, I think that probably will not work for you since rollbar uses a lot of global variables and your last call to rollbar.init will likely be what is used.

I would probably try to explain your use case a bit more, to see if it's something Rollbar wants to support, but it likely will require a decent amount of engineering effort to refactor the library to work that way.

@ianlofs
Copy link

ianlofs commented Aug 14, 2020

I would like to be able to do something like this as well. Actually ideally I would like to be able to create a configured instance of the rollbar client that has the token it needs to route messages appropriately. For my use case I am setting up an Apache Airflow environment that will be shared by multiple teams which will own the running of their DAGs in Airflow. The team provides the their token and the global exception handler uses that token to route the messages. I want to be able to route errors and messages using a given projects token ( we use a token per team ). This way teams can provide a token for what they are working on and can be alerted when their DAGs fail. FWIW I was able to reinitialize by resetting the _initialized variable back to false and the message was routed appropriately.

@terencehonles
Copy link
Contributor

I would like to be able to do something like this as well. Actually ideally I would like to be able to create a configured instance of the rollbar client that has the token it needs to route messages appropriately. For my use case I am setting up an Apache Airflow environment that will be shared by multiple teams which will own the running of their DAGs in Airflow. The team provides the their token and the global exception handler uses that token to route the messages. I want to be able to route errors and messages using a given projects token ( we use a token per team ). This way teams can provide a token for what they are working on and can be alerted when their DAGs fail. FWIW I was able to reinitialize by resetting the _initialized variable back to false and the message was routed appropriately.

Make sure you are reconfiguring rollbar after each reset before sending a new log item otherwise you may be using old config. My comment was assuming you were just initializing with multiple projects, but if you're doing it before each message you should most likely be safe. You may need to use a blocking handler unless all the configuration is picked up and saved locally, otherwise you might end up having a race condition because the non blocking handler uses threads IIRC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants