Deploy-time parameterization of browser applicationID

We pasted the NERUM <script> tag into the <head> element of our index.html as required but changing the applicationID at deploy-time is problematic. The output of our build is a a minified bundle ready to drop into QA, staging or production machines. We build it once and deploy the result to successive machines. However, we do not want development or staging machines metrics reporting to the same applicationID as production for obvious reasons. How do we externalize the applicationID (or licenseKey for that matter) so that it does not have to be burned into our index.html file at build time? I would like to fetch that value at run-time (e.g. an HTTP call) from a service.

Hi @cogitaria - If you extract the javascript for one of the accounts/applications, you should be able to locate the account/application id within. You can then use your automation build tool to change the value to the different account/application based on the environment you are deploying.

Thanks but the issue is not finding or replacing the applicationID in general. Again, we create a binary release and deploy it to any number of systems. All configuration is external, except the NewRelic piece.

Adding a binary stream edit to find and replace the applicationID in the bundle as it’s deployed is what we’re trying to avoid having to do.

Can we make a service call to fetch the key and start monitoring? That’s really what we are asking. That’s much cleaner than patching the binary.

Hi, @cogitaria: This is not something that’s built into the product, but you can certainly create a service, call it from your page to retrieve the application ID and/or license key, and use a technique like the one described below to update New Relic’s Browser agent at runtime:

I would think, though, that by the time you query your service and update the Browser agent, the page will already have loaded, so New Relic’s agent will not be able to measure the page load time, defeating one of the primary purposes of New Relic Browser.

We have a single-page application. The initial page load is just one metric which is easy to obtain without the NR plug-in.

The example from @cstanhope isn’t particularly useful because it’s just moving the problem of configuring the script dynamically to configuring the variables dynamically BEFORE it’s executed.

I believe we can solve this with a self-executing anonymous function (that’s usually how these plug-ins are provided but not in the NREUM case).

@cogitaria I think you’re quite right about being able to do that, it’s just not something that’s built in to the Browser agent by default. Be careful with the timing, though, because the agent does need the app ID and license key to be configured before it executes, because that’s how our servers identify where to route your data. If the agent sent us data without that we would just drop the data, so the agent is configured not to execute at all if it doesn’t have the proper configuration. This keeps the agent from using resources on the client side unnecessarily.