Heroku is a Platform as a Service (PaaS) solution for hosting web applications in various agent languages, including Java. With New Relic, you can extend Heroku with metrics from APM or Browser.
If you use Scala, see Java agent Scala procedures for Heroku.
Compatibility and requirements
- Java 7 or higher
- Maven 3 or higher (if you are using Maven)
- Latest New Relic Java agent version
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.
- Log in to your Heroku account.
- From the APM Add-On Page, select a subscription plan.
- 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. 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
3. 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
-
-
Give your app a meaningful name with this Heroku toolbelt command:
heroku config:set NEW_RELIC_APP_NAME="APP_NAME"
-
Add your New Relic license key:
heroku config:set NEW_RELIC_LICENSE_KEY="LICENSE_KEY"
-
In your
pom.xml
, add thenewrelic-agent
dependency, substitutingX.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>
-
In the
<build>
element ofpom.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
-
- Log in to dashboard.heroku.com.
- Select your app.
- Select Add-ons > New Relic APM.
- From the New Relic UI's account dropdown, select Account settings.
- In the Update your New Relic agent section, download the latest agent release for your Java SE release.
- Unzip the file into your app root.
- Edit
newrelic.yml
to customize theapp_name
setting with a descriptive app name. - Also in
newrelic.yml
, add your license key to thelicense_key
setting.
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.
-
Push your changes to the dyno with this Heroku toolbelt command:
git add . git commit -m 'YOUR COMMIT MESSAGE' git push heroku master
-
Open your app in your browser with this Heroku toolbelt command:
heroku open
- Generate some traffic to your app and wait a few minutes.
- 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, go to Heroku, select Find More Add Ons, and add the 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:
- Heroku and New Relic (additional topics for Heroku users)
- Heroku Dev Center (information on the Heroku site on installing New Relic)