How can I install New Relic in Heroku Play Framework without adding the agent to my git repository?
-
21-12-2019 - |
Question
I have a Scala Play Framework app in Heroku. I want to install New Relic, but I don't want to add the java agent jar to my git repository. I think the repository should exclusively contain code, configuration files and such, maybe with the exception of static assets such as images. Never binary dependencies.
Is there any way of achieving this?
Solution
I found the solution is to add the New Relic binaries from the Maven repository, then to point the Procfile to the right place. The detailed solution is for Scala, but should work in Java too:
Download the newrelic.yml file and add it to your git repository in the root of the Play Framework app.
Add the New Relic dependency to Build.scala:
val appDependencies = Seq( "com.newrelic.agent.java" % "newrelic-agent" % "3.7.0", //Other dependencies here ) val main = play.Project(appName, appVersion, appDependencies)
Add the following to the
web:
entry of your Play Framework app's Procfile (all in one line):-J-javaagent:target/universal/stage/lib/com.newrelic.agent.java.newrelic-agent-3.7.0.jar -J-Dnewrelic.config.file=newrelic.yml
Commit all your changes and push to your Heroku app's git repository.
Wait for Heroku to build and deploy the app, then a few minutes for New Relic to start displaying data.
Drool at New Relic's InfoPorn! :-D
I found the path where the New Relic agent was being downloaded from the Maven repository by connecting to my Heroku app's terminal (heroku run bash
in the CLI) and searching around.