9

With previous version of the Java Play framework, we could provide a command line argent to load monitoring agents. For example, NewRelic could be loaded as

./path/to/start -javaagent:/path/to/newrelic.jar

With the release of the 2.2, the Play team has significantly changed the start script. From what I can tell, it no longer supports javaagents. Has any else gotten NewRelic running with Java Play 2.2+? Play is great, but its useless tech if you can't monitor it in a production environment...

Chris
  • 93
  • 1
  • 4

4 Answers4

14

It seems that you can prefix Java options with -J (in a manner similar to system properties using -D):

$ bin/<app> -J-javaagent:lib/newrelic.jar

Discovered this while poking around in the script itself but it is noted in the usage summary:

$ bin/<app> -h
Usage:  [options]    
...
  -J-X               pass option -X directly to the java runtime
                     (-J is stripped)
...
penfold
  • 1,523
  • 1
  • 14
  • 21
  • Great find!! The -J argument caused the NewRelic agent to get loaded. For some reason the NewRelic logs indicate it's sending data, but NewRelic's web UI isn't updating. I'll report back once I hear from their support team. – Chris Sep 30 '13 at 03:37
  • I seem to be getting data now. Ironically, I think the collection was failing. – penfold Sep 30 '13 at 03:40
  • Interesting. I'm still not getting data and the NewRelic support team says Play 2.2 isn't supported yet. What version of the NewRelic library are you using? – Chris Sep 30 '13 at 22:03
  • I'm using version 2.21.4 (I just noted the latest version from https://newrelic.com/docs/releases/java). It does appear to be working; but the app I'm testing with is trivial. It did pick up an exception (thrown on purpose). This is the first time I've used New Relic though (via Heroku); I suspect it will be best to wait until Play 2.2 is officially supported. – penfold Oct 01 '13 at 02:10
  • hi penfold - I'm not using heroku. Heroku has pretty good support for Java Play and NewRelic. I wonder if they're doing something special... – Chris Oct 02 '13 at 02:12
  • So It looks like I can get the agent started, but it doesn't report any data. My command is './api-1.0-SNAPSHOT/bin/api -J-javaagent:/var/app/api/newrelic/newrelic.jar -Dnewrelic.bootstrap_classpath=true'. It looks like the -Dnewrelic.bootstrap_classpath=true isn't being honored, so no data is sent. If others have this working, I'd love to see the command you're using to start Play... – Chris Oct 15 '13 at 19:47
  • I have the same problem, when I set the loglevel to "finer" I can see a transaction start and a transaction dispatch when using play 2.1. When using play 2.2 there is only a transaction start in the logfile, no dispatch – Kris Pypen Oct 16 '13 at 11:26
  • 1
    I have it working! Now I also have transactions. I needed to upgrade to the latest 3.0.1 agent. – Kris Pypen Oct 16 '13 at 11:53
  • Thanks Kris!! I did NOT click the download link for NewRelic's Java Play agent. Instead I downloaded their Java 3.0.1 package, installed it, used the same command above, and its working. Thanks for pointing me toward the regular 3.0.1 Java package. – Chris Oct 18 '13 at 17:38
1

With the new native packager in Play Framework 2.2 you need to set Java options in the JAVA_OPTS environment variable.

James Ward
  • 29,283
  • 9
  • 49
  • 85
  • Hi James - Great suggestion. When I attempted this, it worked for system properties with the -D flag, but didn't work for -J java options. When I set the JAVA_OPTS export as "-J-javaagent:/path/to/newrelic.jar -Dnewrelic.bootstrap_classpath=true", the javaagent wasn't started. – Chris Sep 30 '13 at 03:24
  • Bummer. I'll investigate why this doesn't work. it seems like it should. – James Ward Sep 30 '13 at 07:05
  • 1
    I just set my JAVA_OPTS="-J-javaagent:path/java.newrelic-agent-3.0.1.jar" and it worked. (using play2.2, new relic, heroku) – Coy Oct 30 '13 at 14:15
0

In Play Framework version 2.2, the application launch script changed to a different directory. To load the javaagent library, it is necessary to specify its full path.

For example, if heroku-javaagent-1.4.jar is in the project's lib directory:

heroku config:set JAVA_OPTS="-Xmx384m -Xss512k -XX:+UseCompressedOops -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -javaagent:/app/lib/heroku-javaagent-1.4.jar=stdout=true,lxmem=true"
Fernando Correia
  • 21,803
  • 13
  • 83
  • 116
0

This works for PlayFramework 2.3.x I copied the agent jar + yml config file to PLAY_APP_ROOT/lib

sbt start -J-javaagent:lib/newrelic.jar
maestr0
  • 5,318
  • 3
  • 28
  • 27