In a previous post, I showed how to report errors to New Relic from an Azure Worker Role. This Cloud Service could be deployed in a number of environments, such as Test and Production. With the NewRelic.AppName setting defined in app.config (or web.config for a Web Role), all deployments will report data under that single application name in New Relic.
Wouldn’t it be nice if we could report data per environment?
Cloud Service projects can contain one or more cloud configuration files (with extension cscfg). These can be used at publish time, to use the set of configuration you want for that particular deployment. Unfortunately New Relic doesn’t support using this cloud configuration out of the box. It only looks at configuration in the applications app/web.config.
Here is one approach to getting around that limitation
Define a new Startup task for the cloud service. These tasks can be batch scripts, or console applications. They can also be batch scripts that start PowerShell scripts.
This Startup task will run a batch file called startup_config.cmd. This command file should be created in the solution, and be set to copy to output on build.
The batch file does little more than run a PowerShell script and direct standard output and error to log files for troubleshooting purposes.
The PowerShell script that is run reads a NewRelic.AppName setting from cloud configuration, loads the app configuration file, and appends the setting to the appSettings section.
As is, this script assumes the setting doesn’t already exist in app config. You might want to change it to update or insert, for example.
You can now easily configure your application to report in New Relic under as many names as you have environments to deploy to.