Configuring New Relic in Java Application
New Relic is one of the popular and industry-leading APM (Application Performance Monitoring) tool. In this post, I am going to explain how to configure New Relic
in a simple Java application in just a few steps.
Step 1: New Relic provides monitoring as a SaaS solution. To send the data to New Relic, first sign-up for an account in https://newrelic.com/. The account can be created in a matter of 2 to 3 minutes which has 14 days of the trial period.
Step 2: Head to the Java application and add the newrelic-java-agent dependency. I am using Maven for build however same version is also available for Gradle. This is going to add the java-agent jar to the project which is needed for instrumentation.
<dependency>
<groupId>com.newrelic.agent.java</groupId>
<artifactId>newrelic-agent</artifactId>
<version>4.12.0</version>
</dependency>
Step 3: Create a filenewrelic.yml
in the project root folder. This file contains all the configuration details of the project related to instrumentation purpose. The newrelic.yml
template can be found at the below location. Copy the content and paste in the newly created file in the project source root folder.
Step 4: Get the unique license_key
from New Relic
logged in account and update the key in newrelic.yml
file as shown below. The app_name
can be customized which will reflect the correct application name.
common: &default_settings
# ============================== LICENSE KEY ===============================
# You must specify the license key associated with your New Relic
# account. For example, if your license key is 12345 use this:
# license_key: '12345'
# The key binds your Agent's data to your account in the New Relic service.
license_key: '<Your License Key>'
... app_name: <Custom Application Name>
...
Step 5: Start the JVM with the java agent path located in as the VM argument. This will look for the agent while starting the application and accordingly configure the instrumentation.
-javaagent:<path to newrelic agent>/newrelic-agent-4.12.0.jar
Step 6: If all the above steps configured correctly at the start of the application below log will be reflected which connects to New Relic
collector.
Send a few transactions from the application once started.
May 23, 2019 21:45:32 -0700 [35694 1] com.newrelic INFO: New Relic Agent: Loading configuration file "newrelic.yml"
May 23, 2019 21:45:32 -0700 [35694 1] com.newrelic INFO: Using default collector host: collector.newrelic.com
Step 7: As New Relic
is configured correctly, let's head to https://one.newrelic.com/ to view the monitoring details from the application.
Navigate to https://one.newrelic.com/ with the earlier created login credentials and verify that the application should be configured populated in New Relic’s Dashboard.

Click on the Application Name (Money Transfer Application) to see the details on the monitoring landing dashboard. As we can see from the below screenshot is that our transactions have been recorded.

Now Click On Explore Performance > Transactions
from the right dropdown, which will take to the Transactions screen where details of each API transaction from the application is laid out.

Select a specific transaction to see the breakdown of each call during the flow.

The Error Analytics
screen lists down all the errors and their rate with other additional information such as a stack trace. This helps to identify and resolve the production issue quicker.

The above application with New Relic configuration can be found at below GitHub repository.
We have seen here is that configuring New Relic to a Java application and start monitoring the metrics is a quick process and only takes a few minutes. Detail documentation on other configurations from java-agent perspective can be found at New Relic’s official web site at https://docs.newrelic.com/docs/agents/java-agent/getting-started/introduction-new-relic-java.
Thanks for reading.