• English日本語한국어
  • Log inStart now

Automatic application naming

The names you give to your applications can help organize your New Relic performance metrics.

New Relic's Java agent reports all transactions and other metrics in a single JVM to the application name specified in newrelic.yml under the setting app_name (for more information about application naming, see Name your Java application). By changing enable_auto_app_naming in newrelic.yml to true, applications will be named for their context, filter, servlet, or request attribute.

This setting allows you to run several web applications in a single JVM while reporting transactions, errors, and metrics to other appropriate applications in the New Relic user interface. Background tasks will still use the default application name from the newrelic.yml.

Important

These configuration changes require a JVM restart to take effect.

This configuration does NOT work with Infinite Tracing enabled.

Caution

Enabling auto app naming will increase the amount of data ingested by the agent. There are various methods to alert on and monitor data ingest.

Application name sources

When you set enable_auto_app_naming to true, New Relic uses the following sources of information to name your applications:

App type

Naming source

Background tasks

The default application name from newrelic.yml

Web transactions

In order by priority:

  • Request attribute (highest priority)
  • Servlet init parameter
  • Filter init parameter
  • Web app context parameter
  • Web app context name (display-name)
  • Web app context path (lowest priority)

Request attribute

The APPLICATION_NAME request attribute takes precedence over any settings in the XML. Set this attribute as early as possible in the web transaction. If called multiple times, the last invocation determines the application name.

Tip

APPLICATION_NAME only works with ServletRequests.

To use the request attribute for fine-grained application naming based on the request URI:

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");
}
...

Servlet init parameter

To set the application name for individual servlets in web.xml using init parameters:

<servlet>
<servlet-name>SqlServlet</servlet-name>
<servlet-class>test.SqlServlet</servlet-class>
<init-param>
<param-name>com.newrelic.agent.APPLICATION_NAME</param-name>
<param-value>MyServletApp</param-value>
</init-param>
</servlet>

The agent obtains the value of the init-param by calling

javax.servlet.ServletConfig#getInitParameter(String)

with the argument com.newrelic.agent.APPLICATION_NAME.

If a web request calls multiple servlets, the init-param of the first servlet to finish has precedence. A servlet that does not have an init-param uses the default application name for the web app.

Besides declaring the application name in XML, you can also set it in your application code by storing an attribute in the javax.servlet.ServletRequest:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
...
request.setAttribute("com.newrelic.agent.APPLICATION_NAME", "MyWebApp");
...

Filter init parameter

If your web app does not have servlets, you can use an init parameter for a filter:

<filter>
<filter-name>SqlFilter</filter-name>
<filter-class>test.SqlFilter</filter-class>
<init-param>
<param-name>com.newrelic.agent.APPLICATION_NAME</param-name>
<param-value>MyFilterApp</param-value>
</init-param>
</filter>

The agent obtains the value of the init-param by calling javax.servlet.FilterConfig#getInitParameter(String) with the argument com.newrelic.agent.APPLICATION_NAME. Servlets takes precedence over filters for application naming, so the init parameter for a filter is used only if no servlets were invoked. The init-param of the first filter to finish has precedence.

Context parameter

To use a context parameter to set the application name:

<context-param>
<param-name>com.newrelic.agent.APPLICATION_NAME</param-name>
<param-value>MyWebApp</param-value>
</context-param>

The agent obtains the value of the context parameter is by calling javax.servlet.ServletContext#getInitParameter(String) with the argument com.newrelic.agent.APPLICATION_NAME. The context parameter takes precedence over the display-name element.

Display name

To determine the application name by using the display-name element in the web.xml:

<display-name>MyWebApp</display-name>

The agent obtains the value of the display-name element by calling javax.servlet.ServletContext#getServletContextName().

Context path

If there is no display-name element, and none of the other higher hierarchy methods are used to set the app name, the application name comes from the context path of the web app. The agent obtains the context path by calling javax.servlet.ServletContext#getContextPath().

The context path is the portion of the request URI that is used to select the context of the request. The context path always comes first in a request URI. For example:

Consider the following URL:

http://example.com/newrelic-axis2-ws/getWeather

In this URL:

  • The request URI is /newrelic-axis2-ws/getWeather.
  • The context path is /newrelic-axis2-ws.
  • The application is named newrelic-axis2-ws.
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.