Java Play 2.2 doesn't support javaagent
Asked Answered
S

4

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...

Standridge answered 28/9, 2013 at 19:16 Comment(0)
S
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)
...
Salamis answered 30/9, 2013 at 2:18 Comment(9)
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.Standridge
I seem to be getting data now. Ironically, I think the collection was failing.Salamis
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?Standridge
I'm using version 2.21.4 (I just noted the latest version from 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.Salamis
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...Standridge
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...Standridge
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 dispatchPentachlorophenol
I have it working! Now I also have transactions. I needed to upgrade to the latest 3.0.1 agent.Pentachlorophenol
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.Standridge
W
1

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

Worcestershire answered 28/9, 2013 at 20:48 Comment(3)
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.Standridge
Bummer. I'll investigate why this doesn't work. it seems like it should.Worcestershire
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)Troyes
L
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"
Laskowski answered 2/1, 2015 at 19:9 Comment(0)
N
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
Need answered 17/2, 2015 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.