The New Relic Java agent is available as a Maven dependency that can be automatically downloaded and installed during your project's build. This has the advantage of not having to check the agent into your project's source control and makes it easier to change versions in the future.
-
Add
newrelic-java
as a dependency. Check Maven Central for the latest version:<dependency> <groupId>com.newrelic.agent.java</groupId> <artifactId>newrelic-java</artifactId> <version>2.15.0</version> <type>zip</type> <scope>runtime</scope> </dependency>
-
Bind the an execution of the
unpack-dependencies
goal to thepackage
phase. This will unzip the agent totarget/dependecy/newrelic
during your project's build:<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.3</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> </configuration> </execution> </executions> </plugin> </plugins> </build>
-
Push these changes to your application:
:::term $ git add pom.xml $ git commit -m 'add newrelic' $ git push heroku master
Add the following flag to your JAVA_OPTS config var on Heroku:
-javaagent:target/dependency/newrelic/newrelic.jar
You can get the current value of your config var with:
::: term
$ heroku config
...
JAVA_OPTS => -Xmx384m -Xss512k -XX:+UseCompressedOops
...
Copy the value and add the Java agent flag:
:::term
$ heroku config:add JAVA_OPTS='-Xmx384m -Xss512k -XX:+UseCompressedOops -javaagent:target/dependency/newrelic/newrelic.jar'
Adding config vars:
JAVA_OPTS => -Xmx384m -Xss512...lic/newrelic.jar
Your pom addition is missing the <executions> tag.