Naming Your Application: All You Need to Know

An earlier blog article described why you need a unique name for your application at the time of deployment. This ‘application name’, also known as app_name or ‘appname’ is used, along with your account id, to keep track of your data

But how do you go about naming your application? The most common way is to use the appropriate setting in your application configuration file. But what is the best way to name it?!  What if I have more than one application on a server or virtual hosts?

Cautions about naming your applications

Before we discuss changing the name, a word of warning. While you can change the appname in your config file at any time, that change will cause the NEW appname to show up on your dashboard along side your OLD one. This produces a discontinuity. There is no way to consolidate the data but the old data will be retained until you decide you no longer need it. Nothing is lost but the second name can be inconvenient. Name your app early.

The documentation describes using the UI to change the displayed application name (in the Applications > Settings’ menu). But this is really only for the UI. It does not change the unique application identifier that is used to collect your data. This is noted  in the dashboard ‘Settings’ page if you look immediately under your new app name, but it is often overlooked.

Naming your applications

Using the configuration files for agent naming assumes that you have a single application reading the config file on the host using the same appname for all the applications on that server. If that is not the case, all is not lost. Several of the agents provide techniques to get around this.

Specify the appname in the code

If you have written your own application and have access to the source, you may specify the appname in your code via an agent API call. The following examples and links will describe these techniques:

PHP — This is the recommended best practice from the New Relic PHP agent engineering team:

[code]
if (extension_loaded(‘newrelic’)) {

newrelic_set_appname (name);
}
[/code]

JAVA — There’s a complete hierarchy of application naming available in the Java Agent Documentation:

[code]
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String requestUri = httpServletRequest.getRequestURI();

if (requestUri.startsWith("/my-special-request/")) {

request.setAttribute("com.newrelic.agent.APPLICATION_NAME",
"MySpecialWebApp");

}


[/code]

RUBY, .NET & NODE.JS — Sorry, you can’t get there from here.

Special techniques for Python and PHP
PYTHON specific environment

By default Python will set the app_name to “Python Application” but there are three ways to set the app_name, and they form a hierarchy.

    • Set the environment variable NEW_RELIC_APP_NAME to the appname string. This should be done in the environment in which the application is started.
    • Set the parameter “app_name” in the newrelic.ini file.  This will take precedence over the environment variable.
    • Set “newrelic.app_name” in the apache/mod_wsgi WSGI environment. The ‘SetEnv’ directive can be used there, or optionally within either a ‘Location’ or ‘Directory’ block, to override configuration settings. This will take precedence over all else.
PHP Specific environment

If you are using the PHP agent in a virtual host environment, there are ‘Per-directory‘ setting options available. These let you set the virtual host environment to override the server configuration appname (set in newrelic.ini) for each virtual host. There are examples for several environments in the documentation so select the appropriate one.

You may notice the construct:

[code]
<IfModule php5_module>

php_value newrelic.appname "Virtual Host 2"

</IfModule>
[/code]

This is included to insure the PHP5 module is loaded before attempting to set it. The only purpose is to protect against using the vhost specification on a system that does not include PHP.  If this does not work, “php5_module” may not be the name used in your environment. The easy solution is to remove <IfModule> and </IfModule>.

rengland@newrelic.com'

View posts by .

Interested in writing for New Relic Blog? Send us a pitch!