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.
Go to one.newrelic.com > APM > (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.
Your New Relic agent download package (
newrelic_agent.zip) contains two templates for using XML instrumentation:
extension.xsdtemplate is the XML schema definition which all custom extensions must follow.
extension-example.xmltemplate 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.
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:
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
Specify an existing extensions directory
To verify the agent read the XML file, first set the Log management to
newrelic.ymlconfiguration file and change the
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.
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.
For an example of a custom instrumentation XML file, see Java XML examples.