raygun4js icon indicating copy to clipboard operation
raygun4js copied to clipboard

Any chance to get options or apiKey from a current instance

Open hwclass opened this issue 6 years ago • 1 comments

Hi guys,

I've checked the source but haven't seen anything about how we can retrieve options or other credentials used to initialize raygun. It would be really useful while developing integration tests for applications. For example, is it possible to do something like the following.:

// init with an api key
rg4js('apiKey', 'RAYGUN-API-KEY-FOR-TEST')
rg4js('enableCrashReporting', true)
rg4js('options', {
   ignore3rdPartyErrors: true,
   ignoreAjaxAbort: true
})

// get results
rg4js('apiKey') // would return 'RAYGUN-API-KEY-FOR-TEST' but returns undefined
rg4js('enableCrashReporting') // returns undefined
rg4js('options') // returns undefined

Note: I know, maybe there could be some security concerns about opening the whole instance to be tracked by end-users. If there is not such a support, we may discuss and I would be the volunteer to integrate such a feature.

hwclass avatar May 14 '18 08:05 hwclass

Hi @hwclass, sorry for the late reply. There isn't a mechanism I know of to this currently. We are open to PRs so if you would like to give this a go then by all means :)

As to the security concerns, the information has to set on the client at some stage anyway so a easier way to get the ApiKey for a given app would be to look at the source code.

BenjaminHarding avatar Jul 06 '18 01:07 BenjaminHarding

Hi @hwclass,

The most straightforward approach I can think of is to maintain your own configuration object for Raygun settings within your application's scope. This way, you can refer to this object whenever you need to access any Raygun options or credentials. Below is an example -

// Example configuration object
const raygunConfig = {
  apiKey: 'YOUR_API_KEY',
  options: {
    // other options
  }
};

// Initialize Raygun with the configuration
Raygun.init(raygunConfig.apiKey, raygunConfig.options);

// Now, raygunConfig can be referred to anywhere in your application!

I will be closing this thread since this can be resolved with the above suggestion. But if you need any additional help, don't hesitate to reach out to us.

Cheers, Sumitra

sumitramanga avatar Feb 05 '24 02:02 sumitramanga