Java agent configuration: Config file

The New Relic Java agent reads its configuration from the newrelic.yml file. By default the agent looks for this file in the directory that contains newrelic.jar. You can override the config file's location by setting the newrelic.config.file system property to a fully qualified file name.

Configuration file structure

The newrelic.yml file is split into stanzas corresponding to different environments:

  • Test
  • Development
  • Staging
  • Production (default)

New Relic applies settings in the common stanza to each of these environments. You can select other environments as the default by setting the newrelic.environment system property to the environment name.

If you edit newrelic.yml, be careful to indent only with two spaces and only where relevant; for example, in stanzas such as error_collector. Other indentation will result in an "Unable to parse configuration file" error upon agent startup. Also a process restart is required when you change any property except log_level and audit_mode.

A newrelic.yml template is available.

Configuration settings precedence

To override any setting in the config file, use a system property override. In certain environments, environment variables can also be used to override both the config file and the system properties. The environment variables primarily exist to support Heroku. When used, server-side configuration overrides all other configuration settings.

java-config-order.png
With the Java agent, server-side configuration overrides all other settings. Environment variables override Java system properties. Java properties override user configuration settings in your newrelic.yml file. User settings override the newrelic.yml default settings.

Configuring the Java extensions directory

The Java agent reads the configuration files on process start up. There are two ways to specify the directory where the files are located:

Create an extensions directory

To create the extensions directory:

  1. Navigate to the directory where newrelic.jar and newrelic.yml are located. Create a directory named extensions.
  2. In newrelic.yml, check that the property extensions.dir is not set.
Specify an existing extensions directory

To use an existing Java extensions directory:

  1. In your newrelic.yml file, locate the common section.
  2. Use the property extensions.dir to specify the location of the file.

General configuration settings

Set these options in the common stanza. To override any of these options, use a newrelic.config prefixed system property.

license_key (REQUIRED)
Type String
Default (none)

This setting is required. You must specify the license key associated with your New Relic account. This key binds your agent's data to your account in the New Relic service.

app_name (HIGHLY RECOMMENDED)
Type String
Default (none)

Defines the application name used to report data to New Relic.

If enable_auto_app_naming is false, the agent reports all data to this application. Otherwise, the agent reports only background tasks (transactions for non-web applications) to this application.

To report data to more than one application, separate the application names with a semicolon. For example, to report data to My Application and My Application 2 use this:

app_name: My Application;My Application 2
agent_enabled
Type Boolean
Default true

Flag to enable the agent. Use this setting to force the agent to run or not run.

apdex_t
Deprecated
Type Float
Default 1.0

The apdex_t threshold in seconds for the application's Apdex score. For Java agent versions 1.2.008 or higher, the apdex_t value is set in the UI and the value in newrelic.yml is ignored. For more information, see Apdex.

appserver_port
Type Integer
Default (none)

Number to differentiate JVMs for the same app on the same machine. New Relic uses host/port for uniqueness, so you can distinguish the JVMs by putting a switch like this into the startup arguments for each JVM:

-Dnewrelic.config.appserver_port=8081

Once you have used appserver_port to name the JVMs and restart them, you should be able to see them individually in the dropdown and in the profiling interface.

This is only a change for New Relic; it doesn't actually affect the port on which the server communicates in any way.

audit_mode
Type Boolean
Default false

Enables plain text logging of all data sent to New Relic to the agent logfile. This setting is dynamic, so running agents will notice changes to newrelic.yml without a JVM restart.

enable_auto_app_naming
Type Boolean
Default false

Enables the reporting of data separately for each web app. Set to true to enable support for auto app naming. The name of each web app is detected automatically and the agent reports data separately for each one. This provides a finer-grained performance breakdown for web apps in New Relic.

See Automatic application naming.

enable_auto_transaction_naming
Type Boolean
Default true

Enables component-based transaction naming. Set to true to enable component-based transaction naming. Set to false to use the URI of a web request as the name of the transaction. For more information, see Naming web transactions.

Unless you implement API calls to name your transactions, disabling auto-transaction naming is very likely to cause Metric grouping issues.

enable_custom_tracing
Type Boolean
Default true

Enables all instrumentation using an @Trace annotation. Disabling this causes @Trace annotations to be ignored.

extensions.dir
Type String
Default (none)

Defines the location of the optional extensions directory. If this property is not set, the agent will look for a subdirectory named extensions in the same directory as newrelic.jar and newrelic.yml.

high_security
Type Boolean
Default false

In order for high security to be enabled, this property must be set to true and the high security property in the New Relic user interface must be enabled. Enabling high security means SSL is turned on, request and message queue parameters are not collected, and queries cannot be sent to New Relic in their raw form.

labels
Type String
Default ""

A dictionary of label names and values that will be applied to the data sent from this agent. May also be expressed as a semi-colon delimited string of colon-separated pairs (for example, Server:One;Data Center:Primary).

max_stack_trace_lines
Type Integer
Default 30

Limits the number of lines the agent collects from each stack trace. Increasing this value may impact performance, because it increases the amount of memory the agent uses and the amount of data sent to New Relic.

proxy_host
Type String
Default (none)

The proxy host through which to connect to the New Relic collector. If a proxy is used, the host setting is required. Other proxy settings are optional.

proxy_password
Type String
Default (none)

The password for proxy authentication. If a proxy is used, the host setting is required. Other proxy settings are optional. The username and password settings will be used to authenticate to Basic Auth challenges from a proxy server.

The Java agent supports Basic (clear text) authentication.

proxy_port
Type String
Default 8080

The proxy host port number. If a proxy is used, the host setting is required. Other proxy settings are optional.

proxy_user
Type String
Default (none)

The username for proxy authentication. If a proxy is used, the host setting is required. Other proxy settings are optional. The username and password settings will be used to authenticate to Basic Auth challenges from a proxy server.

Note: The Java agent supports Basic (clear text) authentication.

send_data_on_exit
Type Boolean
Default false

Enable delayed JVM shutdown to give the agent a chance to send latest metric data to New Relic before JVM shutdown.

send_data_on_exit_threshold
Type Integer
Default 60

The number of seconds after which the agent will use the send_data_on_exit setting.

send_environment_info
Type Boolean
Default true

Enable reporting of JVM settings to New Relic.

send_jvm_props
Type Boolean
Default true

When set to true, JVM properties will be sent to New Relic.

ssl
Type Boolean
Default true

Requires connections to New Relic servers to go over SSL.

The agent communicates with New Relic via https by default. If you want to communicate with newrelic via http, then turn off SSL by setting this value to false.

This work is done asynchronously to the threads that process your application code, so response times will not be directly affected by this change.

sync_startup
Type Boolean
Default false

Enable the agent to connect New Relic servers immediately upon app startup.

Logging configuration

These are part of the general configuration variables. They are broken out here because they are frequently tweaked for debugging.

Some of the logging configuration variables are dynamic and do not need a server restart for them to take effect. For instance, if log files are growing too quickly, log_level can be set to a less verbose setting to reduce the reporting rate.

Here is the order of precedence for configuration variables affecting log rotation.

  • If log_daily is true, other log rotation settings are ignored.
  • If log_file_count is 1 or 0, the size limit is ignored.
  • Finally, the agent applies log_limit_in_kbytes.

Depending on the growth rate, it is possible for the log file size to exceed the configured value by a small amount.

log_daily
Type Boolean
Default false

Set to true to roll the logs daily. Overrides the other configuration variables that affect log rotation.

log_file_count
Type Integer
Default 1

The maximum number of log files to keep when using log rotation.

log_file_name
Type String
Default newrelic_agent.log

The unqualified log file name or the string STDOUT which will log to standard out.

log_file_path
Type String
Default (same directory as newrelic.jar)

The log file path.

log_level
Type String
Default info

The log verbosity level.

The agent uses its own log file to keep its logging separate from that of your application. Valid options, in order of verboseness, are:

  • off
  • severe
  • warning
  • info
  • fine
  • finer
  • finest

This setting is dynamic, so running agents will notice changes to newrelic.yml without a JVM restart.

log_limit_in_kbytes
Type Integer
Default 0

The log file size in kilobytes at which log files are rotated. Set to 0 for no limit.

Attributes

To set these options, use the attributes stanza. To override them, use a newrelic.config.attributes prefixed system property.

Attributes are key-value pairs that provide information for transaction traces, traced errors, browser monitoring, and transaction events. There is also an attribute stanza under each destination. For more information, see Java agent attributes, Enabling and disabling attributes, and Attribute examples.

enabled
Type Boolean
Default true

This setting can be used to turn on or off all attributes.

include
Type List of Strings
Default (none)

If attributes are enabled, attribute keys found in this list will be sent to New Relic. Keys in the list should be separated by a comma as shown below:

 key1, key2, key3

Rules for attributes can be found on the agent attributes page.

exclude
Type List of Strings
Default (none)

All attribute keys found in this list will not be sent to New Relic. Keys in the list should be separated by a comma as shown below:

 key1, key2, key3

Rules for attributes can be found on the agent attributes page.

Transaction tracer

These options are set in the transaction_tracer stanza and can be overridden by using a newrelic.config.transaction_tracer prefixed system property.

Transaction tracing captures deep information about slow transactions and sends this to the New Relic service once a minute. The transaction includes the exact call sequence of the transactions, including any query statements issued.

Do not use brackets [suffix] at the end of your transaction name. New Relic automatically strips brackets from the name. Instead, use parentheses (suffix) or other symbols if needed.

enabled
Type Boolean
Default true

The transaction tracer is enabled by default. Set this to false to turn it off.

explain_enabled
Type Boolean
Default true

Determines whether the agent will capture the EXPLAIN plan for slow queries. Only supported for MySQL and PostgreSQL.

explain_threshold
Type Float
Default 0.5

Threshold in seconds for query execution time below which the EXPLAIN plan will not be captured. Relevant only when explain_enabled is true.

log_sql
Type Boolean
Default false

Set to true to enable logging of queries to the agent log file instead of uploading to New Relic. Queries are logged using the record_sql mode.

record_sql
Type String
Default obfuscated

When the transaction tracer is on, query statements can optionally be recorded. The recorder has three modes:

  • off: Send no queries.
  • raw: Send the query statement in its original form (optionally obfuscate the fields listed in the obfuscate_sql_fields setting).
  • obfuscated: Strips out numeric and string literals.
stack_based_naming (Play 2.x+ only)
Type Boolean
Default False

This option is for Play 2.x+ only. Play/Scala instrumentation can use Thread.getStackTrace() to improve tracer naming, but at the cost of increased overhead.

Defaulted to true until Java agent version 3.12.1, when it was changed to false.

stack_trace_threshold
Type Integer
Default 0.5

This is the threshold at which segments will be given a stack trace in the transaction trace.

top_n
Type Integer
Default 20

Use this setting to control the variety of your transaction traces. top_n is an integer that represents the number of unique, slow transactions that traces will be created for.

A value of 0 would mean that only the slowest transaction is always traced. This is considered not to be optimal, though, because you may have one or two transactions that are always the slowest, and repeatedly seeing those same transaction traces will probably not give you much value. The top_n setting makes it so that, if the same transaction is often the slowest, the Java agent will, over time, sample the slowest n transactions, giving you greater variety and more insight into your application.

Make this value lower if you want transaction traces to more accurately reflect the actual slowest transactions in your app. Make the value higher if you want to sample a more diverse array of transactions.

transaction_threshold
Type String (float)
Default apdex_f

The time threshold used to determine when a transaction is eligible for being traced. When the response time of a transaction exceeds this threshold, a transaction trace will be recorded and sent to New Relic.

The default is apdex_f (default), which sets the threshold to be the "Frustrated" Apdex level (four times the apdex_t value). You can also set a specific time threshold by entering a float value that represents a number of seconds.

For more about Apdex, see Apdex. For more on transaction trace basics, see Transaction traces.

slow_query_whitelist
Type String
Default (none)

By default, high security mode does not allow the agent to collect Slow Queries. Enable this option to collect Cassandra queries from the DataStax driver, even with high security enabled. If you don't use high security, the agent collects slow queries automatically.

For DataStax driver 2.1.2, add this whitelist rule:

  transaction_tracer:
      slow_query_whitelist: 
       'com.newrelic.instrumentation.cassandra-datastax-2.1.2'

For DataStax driver 3.0.0, add this whitelist rule:

  transaction_tracer:
      slow_query_whitelist: 
       'com.newrelic.instrumentation.cassandra-datastax-3.0.0'
attributes.enabled
Type Boolean
Default true

This setting can be used to turn on or off all attributes for transaction traces. If attributes.enabled at the root level is false, no attributes will be sent to transaction traces regardless on how this property (transaction_tracer.attributes.enabled) is set.

attributes.include
Type List of strings
Default (none)

If attributes are enabled for transaction traces, all attribute keys found in this list will be sent to New Relic in transaction traces. For more information, see the agent attribute rules.

attributes.exclude
Type List of Strings
Default (none)

All attribute keys found in this list will not be sent to New Relic in transaction traces. For more information, see the agent attribute rules.

Browser monitoring

These options are set in the browser_monitoring stanza and can be overridden by using a newrelic.config.browser_monitoring prefixed system property.

New Relic Browser's page load timing feature (sometimes referred to as real user monitoring or RUM) gives you insight into the performance real users are experiencing with your website. This is accomplished by measuring the time it takes for your users' browsers to download and render your web pages by injecting a small amount of JavaScript code into the header and footer of each page.

auto_instrument
Type Boolean
Default true

By default the agent automatically inserts API calls in compiled JSPs to inject the monitoring JavaScript into web pages. Set this attribute to false to turn off this behavior.

disabled_auto_pages
Type Comma-separated list of strings
Default (none)

When auto_instrument is true, by default all pages are instrumented. List all pages that you want the auto instrumentation to skip here. You can still use manual instrumentation on these pages.

For example:

browser_monitoring:
  disabled_auto_pages: /WEB-INF/jsp/testpage_1.jsp, /WEB-INF/jsp/testpage_2.jsp
attributes.enabled
Type Boolean
Default false

This setting can be used to turn on or off all attributes for browser monitoring. This is the data which gets sent to page views in Insights. If attributes.enabled is false at the root level, no attributes will be sent up in browser monitoring regardless on how this property under browser_monitoring is set.

attributes.include
Type List of Strings
Default (none)

If attributes are enabled for browser_monitoring, all attribute keys found in this list will be sent to New Relic in page views. For more information, see the agent attribute rules.

attributes.exclude
Type List of Strings
Default (none)

All attribute keys found in this list will not be sent to New Relic in page views. For more information, see the agent attribute rules.

Cross application tracer

These options are set in the cross_application_tracer stanza and can be overridden by using a newrelic.config.cross_application_tracer prefixed system property.

Cross application tracing adds request and response headers to external calls using the Apache HttpClient libraries. This provides better performance data when calling applications monitored by other New Relic Agents.

enabled
Type Boolean
Default true

Cross application tracing is enabled by default. Set this to false to turn it off.

Error collector

These options are set in error_collector stanza and can be overridden by using a newrelic.config.error_collector prefixed system property.

The error collector captures information about uncaught exceptions and sends them to New Relic for viewing.

enabled
Type Boolean
Default true

Enable error collection.

ignore_errors
Type Comma-separated list of Strings
Default (none)

String containing a comma-separated list of full exception class names that should not be treated as errors.

For example:

error_collector:
  ignore_errors: some.other.MyException
ignore_status_codes
Type Comma-separated list of strings
Default 404

A comma-separated list of HTTP status codes that should not be treated as errors.

If this property is commented out in the newrelic.yml configuration file, then 404 status codes will automatically be ignored. When using server-side configuration, the status code 404 must be specified in order for it to be ignored.

This setting is dynamic, so running agents will notice changes to newrelic.yml without a JVM restart.

attributes.enabled
Type Boolean
Default true

This setting can be used to turn on or off all attributes for traced errors. If attributes.enabled is false at the root level, then no attributes will be sent to traced errors regardless on how this property under error_collector is set.

attributes.include
Type List of strings
Default (none)

If attributes are enabled for traced errors, all attribute keys found in this list will be sent to New Relic in traced errors. For more information, see the agent attribute rules.

attributes.exclude
Type List of strings
Default (none)

Attribute keys found in this list will not be sent to New Relic in traced errors. For more information, see the agent attribute rules.

Thread profiler

These options are set in the thread_profiler stanza and can be overridden by using a newrelic.config.thread_profiler prefixed system property.

Thread profiler measures wall clock time, CPU time, and method call counts in your application's threads as they run.

enabled
Type Boolean
Default true

Enable the thread profiler.

Transaction events

These options are set in the transaction_events stanza and can be overridden by using a newrelic.config.transaction_events prefixed system property.

Transaction events provide the data for displaying histograms and percentiles in the UI.

This stanza used to be called analytic_events. If your configuration file still uses analytic_events, update your agent to use transaction_events

enabled
Type Boolean
Default true

Enable the transactions events service.

max_samples_stored
Type Integer
Default 2000

The maximum number of data transaction samples stored in memory for the application.

attributes.enabled
Type Boolean
Default true

This setting can be used to turn on or off all attributes for transaction events. If attributes.enabled is false at the root level, then no attributes will be sent to transaction events regardless on how this property under transaction_events is set.

attributes.include
Type List of Strings
Default (none)

If attributes are enabled for transaction events, all attribute keys found in this list will be sent to New Relic in transaction events. For more information, see the agent attribute rules.

attributes.exclude
Type List of Strings
Default (none)

All attribute keys found in this list will not be sent to New Relic in transaction events. For more information, see the agent attribute rules.

Hostname configuration

These options are set in the process_host stanza and can be overridden by using a newrelic.config.process_host prefixed system property.

These properties are used for configuring the hostname displayed in the UI:

display_name
Type String
Default (none)

Set a display name to decorate the "host:port" label in the New Relic UI.

ipv_preference
Type String
Default 4

If the hostname can not be determined, then the IP address of the host will be used. This property determines whether the IPv4 or IPv6 address should be used. The default is IPv4.

Custom instrumentation

These options set in the class_transformer stanza and can be overridden by using a newrelic.config.class_transformer prefixed system property.

trace_annotation_class_name
Type String
Default (none)

String containing the full class name of the annotation class the agent uses to determine which user-specified methods to instrument. For more information about custom annotations, see Java custom metric collection.

com.newrelic.instrumentation.servlet-user
Type Boolean
Default false

Enable this option to capture the userPrincipal name. This name is included as a transaction trace attribute, and can be queried in Insights.

System properties

You can override any setting in the newrelic.yml file by setting a system property. The system property corresponding to a given setting in the config file is setting name prefixed by newrelic.config. For example, the system property for the log_level setting is newrelic.config.log_level.

For settings nested in stanzas, prepend the stanza name to the setting name. For example, the system property for the enabled setting in the transaction_tracer stanza is newrelic.config.transaction_tracer.enabled.

In addition to overriding configuration settings, the following system properties are recognized by the agent:

newrelic.config.process_host.display_name
Type String
Default (none)

Set a display name to decorate the "host:port" label in the New Relic UI. Requires Java agent 3.17 or higher.

newrelic.config.file
Type String
Default (none)

String containing a fully qualified path to the newrelic configuration file. If empty, the agent assumes newrelic.yml is in the same directory as newrelic.jar.

newrelic.debug
Type Boolean
Default (none)

Enable debug logging.

newrelic.environment
Type String
Default (none)

String containing the environment configuration for the agent to use.

newrelic.home
Type String
Default (none)

String containing the home directory of agent. This defaults to the same directory as the agent jarfile.

newrelic.logfile
Type String
Default newrelic_agent.log

String containing the name of the agent log file.

Environment variables

Environment variables below take the highest precedence and override the system properties and yml config settings. You can set environment variables using the export VARNAME=value command. If you want it set permanantly, add the export line to a file such as ~/.bashrc or ~/.bash_profile.

NEW_RELIC_APP_NAME
Type String
Default (none)

Contains the application name under which to report data to New Relic.

Set the name of your application as you'd like it show up in New Relic.

If enable_auto_app_naming is false, the agent reports all data to this application. Otherwise, the agent reports only background tasks (transactions for non-web applications) to this application.

To report data to more than one application, separate the application names with a semicolon ;. For example, to report data to My Application and My Application 2:

app_name: My Application;My Application 2
NEW_RELIC_PROCESS_HOST_DISPLAY_NAME
Type String
Default (none)

Set a display name to decorate the "host:port" label in the New Relic UI.

NEW_RELIC_LICENSE_KEY (REQUIRED)
Type String
Default (none)

Contains your New Relic account license.

You must specify the license key associated with your New Relic account. This key binds your agent's data to your account in the New Relic service.

NEW_RELIC_LOG
Type String
Default newrelic_agent.log

The unqualified log file name or the string STDOUT which will log to standard out.

Cloud platform utilization

These options are set in the utilization stanza and can be overridden by using a newrelic.config.utilization prefixed system property.

The agent collects utilization information and sends it to the New Relic service to determine pricing. The agent can collect information from Amazon Web Services (AWS) EC2 instances, and Docker containers.

detect_aws
Type Boolean
Default true

Determines whether the agent polls AWS metadata API.

detect_docker
Type Boolean
Default true

Determines whether the agent reads Docker information from the file system.

For more help

Additional documentation resources include:

Join the discussion about Java monitoring in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.