Skip to content
Richard Kerslake By Richard Kerslake Engineer I
Using a different New Relic application name per environment with Azure Cloud Services

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.

Azure Weekly is a summary of the week's top Microsoft Azure news from AI to Availability Zones. Keep on top of all the latest Azure developments!

The batch file does little more than run a PowerShell script and direct standard output and error to log files for troubleshooting purposes.

The best hour you can spend to refine your own data strategy and leverage the latest capabilities on Azure to accelerate your road map.

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.

Richard Kerslake

Engineer I

Richard Kerslake

Richard has a background in financial services, working on large scale distributed trading systems. Richard has a passion for delivering real business value to endjin’s customers, who are seeking to take advantage of Microsoft Azure and the Cloud.

Richard worked at endjin between 2014-2017.