{"id":415,"date":"2016-02-20T16:52:07","date_gmt":"2016-02-20T16:52:07","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=415"},"modified":"2016-02-20T16:52:07","modified_gmt":"2016-02-20T16:52:07","slug":"adding-new-relic-to-a-heroku-play-2-application","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2016\/02\/20\/adding-new-relic-to-a-heroku-play-2-application\/","title":{"rendered":"Add New Relic in Heroku using Play 2 (Java) Application"},"content":{"rendered":"<h1>Installing New Relic in Heroku using a Play 2.4.x (Java) Application<\/h1>\n<p>Hi guys, just wanted to write a small post about installing New Relic on a Play Framework App (version 2.4.x) in Heroku. I struggled a bit with some of the instructions I found through the internet (including Heroku&#8217;s and New Relic&#8217;s).<\/p>\n<p>What I did to make it work:<\/p>\n<h2>Install the New Relic Addon through Heroku&#8217;s interface<\/h2>\n<div id=\"attachment_416\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic.png\" rel=\"attachment wp-att-416\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-416\" class=\"size-full wp-image-416\" src=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic.png\" alt=\"New Relic Installation Screen\" width=\"600\" height=\"276\" srcset=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic.png 600w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-300x138.png 300w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-500x230.png 500w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-416\" class=\"wp-caption-text\">New Relic Installation Screen<\/p><\/div>\n<p>This will\u00a0install the add-on and\u00a0configure somethings for you (like environment variables). If you do <strong>`heroku config<\/strong>` you&#8217;l see the following variables:<\/p>\n<ul>\n<li class=\"p1\"><span class=\"s1\">NEW_RELIC_APP_NAME:<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0APP_NAME<\/span><\/span><\/li>\n<li class=\"p1\"><span class=\"s1\">NEW_RELIC_LICENSE_KEY: <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0\u00a0YOUR_LICENSE_KEY<\/span><\/span><\/li>\n<li class=\"p1\"><span class=\"s1\">NEW_RELIC_LOG: <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>stdout<\/span><\/li>\n<\/ul>\n<p>In order for the addon to work you need to enable it&#8217;s Java agent, by adding the dependencies to your build.sbt file:<\/p>\n<blockquote>\n<p class=\"p1\">libraryDependencies ++= <span class=\"s1\">Seq<\/span>(<\/p>\n<p class=\"p1\">\u00a0 \/\/Your other dependencies<\/p>\n<p class=\"p1\">\u00a0 &#8220;com.newrelic.agent.java&#8221; % &#8220;<span class=\"s1\">newrelic<\/span>-agent&#8221; % &#8220;3.25.0&#8221;,<\/p>\n<p class=\"p1\">\u00a0 \u00a0&#8220;com.newrelic.agent.java&#8221; % &#8220;<span class=\"s1\">newrelic<\/span>&#8211;<span class=\"s1\">api<\/span>&#8221; % &#8220;3.25.0&#8221;<\/p>\n<p class=\"p1\">)<\/p>\n<\/blockquote>\n<p class=\"p1\">Notice that at the time of writing ( 20\/02\/2016 &#8211; February 20th ) the latest version of the agent is 3.25. You should always check the <a href=\"http:\/\/mvnrepository.com\/artifact\/com.newrelic.agent.java\/newrelic-api\">latest version at maven central<\/a> and use that.<\/p>\n<p class=\"p1\">Now you need the &#8220;newrelic.yml&#8221; configuration file. You can download when you configure your account in new relic. Once you go to your New Relic account page you&#8217;ll see the following screen :\u00a0Choose &#8220;Java&#8221;.<\/p>\n<p class=\"p1\"><a href=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-1.png\" rel=\"attachment wp-att-417\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-417\" src=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-1.png\" alt=\"new_relic-1\" width=\"600\" height=\"210\" srcset=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-1.png 600w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-1-300x105.png 300w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new_relic-1-500x175.png 500w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a>After you choose Java, the next screen will show this:<\/p>\n<p class=\"p1\"><a href=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new-relic-3.png\" rel=\"attachment wp-att-418\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-418\" src=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new-relic-3.png\" alt=\"new-relic-3\" width=\"500\" height=\"451\" srcset=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new-relic-3.png 500w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new-relic-3-300x271.png 300w, http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2016\/02\/new-relic-3-333x300.png 333w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p class=\"p1\">Click the <strong>&#8220;Download the Java agent&#8221;<\/strong> button. This will download a zip file with the java agent and the <strong>newrelic.yml<\/strong> file. My suggestion is copy the newrelic.yml file to the Play Framework&#8217;s conf directory ( <strong>conf\/newrelic.yml<\/strong> ).<\/p>\n<p class=\"p1\">Add all the changes to git, and push to heroku.<\/p>\n<blockquote>\n<p class=\"p1\">git add build.sbt<\/p>\n<p class=\"p1\">git add conf\/newrelic.yml<\/p>\n<p class=\"p1\">git commit -m &#8216;Add new relic addon&#8217;<\/p>\n<p class=\"p1\">git push heroku master<\/p>\n<\/blockquote>\n<p class=\"p1\">Now you only to configure the environment variables to run the agent.<\/p>\n<blockquote>\n<p class=\"p1\"><span class=\"s1\">heroku config:set JAVA_OPTS=&#8221;Xmx334m -Xss512k -XX:+UseCompressedOops -javaagent:target\/universal\/stage\/lib\/com.newrelic.agent.java.newrelic-agent-3.25.0.jar -Dnewrelic.config.file=conf\/newrelic.yml<\/span><\/p>\n<\/blockquote>\n<p class=\"p1\">Now, I&#8217;m not sure if\u00a0<em>target\/universal\/stage\/lib\/com.newrelic.agent.java.newrelic-agent-3.25.0.jar\u00a0<\/em>will be the same throughout time, but if you get errors like &#8220;cannot open zip file&#8221; or &#8220;cannot read manifest&#8221; I suggest you do the following in your terminal:<\/p>\n<blockquote>\n<p class=\"p1\">heroku run bash<\/p>\n<\/blockquote>\n<p class=\"p1\">Once inside the web dyno, look around and find where the new-relic jar file is and point the environment variable to it.<\/p>\n<p class=\"p1\">Hopefully, that&#8217;s all you need. I did encounter other issues, but mostly related by not having the newrelic.yml file in the right place (or not having the configuration pointing to the right place).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing New Relic in Heroku using a Play 2.4.x (Java) Application Hi guys, just wanted to write a small post about installing New Relic on a Play Framework App (version 2.4.x) in Heroku. I struggled a bit with some of &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2016\/02\/20\/adding-new-relic-to-a-heroku-play-2-application\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,4,39],"tags":[55,45,40],"class_list":["post-415","post","type-post","status-publish","format-standard","hentry","category-heroku","category-java","category-play-framework","tag-heroku","tag-java","tag-play"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=415"}],"version-history":[{"count":2,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":420,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/415\/revisions\/420"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}