Java agent and Heroku

If you enable Heroku's New Relic agent add-on, you can monitor your applications that are hosted on Heroku in APM, Browser, and Insights. Heroku is a Platform as a Service (PaaS) solution for hosting web applications in various agent languages, including Java.

Compatibility and requirements

1. Enable the New Relic agent add-on in Heroku

After you ensure that you meet the requirements, enable the New Relic agent add-on in Heroku.

You must deploy your Java app to Heroku, following the Heroku instructions at least through the Deploy the app step, before you can enable the New Relic agent add-on.

  1. Log in to your Heroku account.
  2. From the New Relic APM Add-On Page, select a subscription plan.
  3. Select Install New Relic APM, and then select your target app from the dropdown.

Installing the add-on automatically creates a New Relic account and configures access for Heroku servers.

2. Configure your Heroku environment for New Relic

After you provide the path to the jar file, configure your Heroku environment for New Relic, depending on your platform:

Maven configuration
  1. Give your app a meaningful name with this Heroku toolbelt command:

    heroku config:set NEW_RELIC_APP_NAME="APP_NAME"
  2. Add your New Relic license key:

    heroku config:set NEW_RELIC_LICENSE_KEY="LICENSE_KEY"
  3. In your pom.xml, add the newrelic-agent dependency, substituting X.Y.Z with the latest Java agent version. Recommended: To ensure proper formatting is applied and contents do not contain sensitive information, format the syntax using http://codebeautify.org/xmlviewer.

    <dependency> 
     <groupId>com.newrelic.agent.java</groupId>
     <artifactId>newrelic-java</artifactId>
     <version>X.Y.Z</version>
     <scope>provided</scope>
     <type>zip</type>
    </dependency> 
  4. In the <build> element of pom.xml, customize the build so it downloads the agent:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
              <execution>
                <id>unpack-newrelic</id>
                <phase>package</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeGroupIds>com.newrelic.agent.java</includeGroupIds>
                  <includeArtifactIds>newrelic-java</includeArtifactIds>
                  <overWriteReleases>false</overWriteReleases>
                  <overWriteSnapshots>false</overWriteSnapshots>
                  <overWriteIfNewer>true</overWriteIfNewer>
                  <outputDirectory>${project.basedir}</outputDirectory>
                  <destFileName>newrelic</destFileName
                </configuration>
              </execution>
            </executions>
          </plugin>
Manual configuration
  1. Log in to dashboard.heroku.com.
  2. Select your app.
  3. Select Add-ons > New Relic APM.
  4. From the New Relic UI's account dropdown, select Account settings.
  5. In the Update your New Relic agent section, download the latest agent release for your Java SE release.
  6. Unzip the file into your app root.
  7. Edit newrelic.yml to customize the app_name setting with a descriptive app name.
  8. Also in newrelic.yml, add your license key to the license_key setting.

3. Provide the path to the jar file

After you enable the New Relic agent add-on, pass the javaagent flag to the java process and provide the path to the jar file by editing your Procfile.

Deploy to Heroku

If you deploy to Heroku, the location of the jar file for both Maven and manual configuration is in the app's root folder in a directory called newrelic.

Example:

web: java -javaagent:/app/newrelic/newrelic.jar -jar target/HELLOWORLD.jar
Deploy locally

If you deploy locally, your jar file might be in a different directory. If it is, replace PATH/TO/NEWRELIC.JAR with the path to the jar file in your local directory.

Example:

web: java -javaagent:PATH/TO/NEWRELIC.JAR -jar target/HELLOWORLD.jar

4. Push your changes and open the app

After you configure your Heroku environment for New Relic, push your changes and open the app to monitor it with New Relic.

  1. Push your changes to the dyno with this Heroku toolbelt command:

    git add .
    git commit -m 'YOUR COMMIT MESSAGE'
    git push heroku master
  2. Open your app in your browser with this Heroku toolbelt command:

    heroku open
  3. Generate some traffic to your app and wait a few minutes.
  4. Check your app's performance in Heroku by selecting your app and then selecting the New Relic add-on.

If no data appears or if you have problems, follow the troubleshooting tips.

Troubleshoot

Here are some tips to help you troubleshoot:

  • If you don't see the New Relic add-on after you generate traffic, to to Heroku, select Find More Add Ons, and add the New Relic APM add-on.
  • If no data appears after waiting a few minutes, follow the troubleshooting procedures for Heroku (Java).

For more help

Additional documentation resources include:

Recommendations for learning more: