raygun4js
raygun4js copied to clipboard
raygun4js only initialises if apiKey is set when `onLoadHandler` is called
This makes it difficult to initialise raygun4js asynchronously, which is becoming more common.
Related: #453, #383, #259
We've come across this issue today and did some digging / reproduction on the issue.
Please see this minimum reproduction and readme here: https://github.com/Codex-/rg4js-init-issue
The issue is that in a lot of cases a key is configured for raygun after the library has initialised, to work around this a consumer can call rg4js('boot'); (typescript typings pr raised for the typings issue: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61397 )
I have a few ideas how this could be resolved but wanted to bounce ideas with the raygun team before I make a PR. Simplest thing would be to flag is onLoadHandler has been executed, then if an API key is configured after this has been executed, simply execute onLoadHandler again (which is what people are effectively doing by manually calling boot).
Another would be a stepping retry as a floated promise.
Let me know your thoughts :)
Hey @Codex- , thanks for the reproduction and types PR!
@Widdershin is currently away for a bit, but I've spoken to @darcythomas and we can take a look if you want to make a PR. The simplest approach seems fine for now 👍
No problem at all, I've raised #474 now with a fix :)
Also, if you haven't seen it, I have also raised: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61397
This is to add the missing typing for calling 'boot', as users were doing some spooky casting to get around the missing type 😅