• EnglishEspañol日本語한국어Português
  • Log inStart now

Java instrumentation by XML

For your New Relic-monitored Java application, one custom instrumentation method is to use an XML file to specify your app methods that should be instrumented. The Java agent will read the XML file and instrument the relevant classes on startup; XML files added to the extensions directory after startup do not require a JVM restart to be detected.

See Java agent custom instrumentation for a description of the custom instrumentation options and the reasons to use them.

Accessing your XML file

Go to one.newrelic.com > All capabilities > APM & services > (select an app) > Settings > Instrumentation. From here you can:

  • Download a sample XML file. (You can do this from the pop-up that appears when you click Import an XML file.)
  • Select an edit existing XML file.
  • Search the instrumentation history.

XML file structure

Your New Relic agent download package (newrelic_agent.zip) contains two templates for using XML instrumentation:

  • The extension.xsd template is the XML schema definition which all custom extensions must follow.
  • The extension-example.xml template is an example. This file instruments some of the basic JDK methods. If you edit and rename this file, ensure you modify the name="extension-example" attribute to match the new filename.

For more information about the properties in the extension.xsd template, see the XML file format overview.

XML file validation

Before starting your application, validate your XML file using New Relic's command line tool. The command line tool can only be used when your classes are in a jar. There are two ways to validate your XML instrumentation:

The application is run with the newrelic.jar. The call must contain the keyword instrument followed by the -file flag with the path to your XML file. The property -debug is optional and may be set to true to provide more information during the validation.

The tool will:

  • Validate the XML syntax.
  • Check that each class to be instrumented is present on the class path.
  • Check that each method is contained in the appropriate class.

If the XML file is valid, you will see a pass statement printed to the terminal:

PASS: The extension at file.txt was successfully validated.

If the XML fails validation, you will see a failure message printed to the terminal:

FAIL: reason

XML file location

The Java agent reads any XML files in the extensions directory on process start up. The extensions directory is also read every harvest cycle. XML files added to this directory during runtime will be read within a few minutes, so they do not require a JVM restart.

There are two ways to specify the XML file location:

XML file location options


Create an extensions directory

  1. In the directory where the newrelic.jar and newrelic.yml is located, create a directory named extensions.
  2. Put the XML file in this directory with a .xml extension.
  3. In newrelic.yml, check that the property extensions.dir is not set.

Specify an existing extensions directory

  1. In the newrelic.yml configuration file under the common section, use the property extensions.dir to specify the directory where the XML file is located.
  2. Make sure the file is in the specified directory and that the file has a .xml extension.

Verify the file was read

To verify the agent read the XML file, first set the Log management to finer:

  1. Edit the newrelic.yml configuration file and change the log_level property:

    log_level: finer
  2. Start or restart the application.

If the read was successful, logs/newrelic_agent.log will indicate this in a statement similar to:

Reading custom extension file /path/to/file.xml

If no statement appears in logs/newrelic_agent.log, then the XML file was not found. Check the location of the XML file, and ensure the New Relic process has read access to the file.

Multiple XML files

While using a single XML file is preferred, you can use multiple custom XML files. These files will all be instrumented as long as the extension name in the files is unique.

  • If two custom XML files contain the same extension name, then the one with the highest version will be implemented and the other will be ignored.
  • If the two files have the same name and version, then the first file read by the agent will be implemented and the other will be ignored.


Prior to 2.10.0, YAML files could be used for custom instrumentation. These legacy YAML files are still supported. However, new users should use XML files for custom instrumentation.

Legacy users: If both a YAML and XML file exist with the same extension name, only the XML file will be instrumented. The YAML file will be ignored. If you want both the YAML and XML files to be instrumented, give each file a different extension name.

Example XML file

For an example of a custom instrumentation XML file, see Java XML examples.

Copyright © 2024 New Relic Inc.

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