Is it possible to run Play Framework 2.0 server with a javaagent?
Asked Answered
T

4

5

I would like to be able to run the Play Framework 2.0 server with a javaagent.

Some resources on the web (see here and here ) suggest that this could be done simply by appending -javaagent:/path/to/agent.jar to play run but it doesn't seems to work for me.

Any clues?

Tempura answered 13/6, 2012 at 10:3 Comment(0)
S
2

There is no clean way to pass the -javaagent parameter to the java command invocation with play 2.0.1-2.0.4 without modifying a script.

I was able to get a javaagent working using the following technique:

# Modify the play/framework/build script to include an extra environment variable
sed -i 's/^java\( \${PLAY_OPTS}\)\?/java ${PLAY_OPTS}/' ${playPath}/framework/build

Then it is possible to pass the -javaagent param like this:

export PLAY_OPTS='-javaagent:/lib/newrelic/newrelic.jar'

${playPath}/play -Dconfig.file=conf/prod.conf -Dlogger.file=conf/prod-logger.xml start


Update

An unfortunate sidenote- I just found out from New-Relic support that New-Relic definitely does not support play-framework 2.x right now (2012-10-04).


Sadowski answered 4/10, 2012 at 20:32 Comment(0)
S
2

I'm using it in Heroku, working fine like follows (in my Procfile):

  play ${JAVA_OPTS} ${MYCONFIG} -javaagent:/newrelic/newrelic.jar run

My newrelic folder is on root, same level as app

Sherbrooke answered 13/6, 2012 at 13:2 Comment(1)
@PereVillega heroku is probably using a custom play script, since the original one will pass -javaagent as an application parameter, instead of as a JVM parameter. Anyway, I'm glad to know that New Relic agent is working with Play 2.0. :-)Cutaway
S
2

The java command line for SBT is defined in the "build.bat" batch file (Win) or "build" shell script (U*X) located in the %PLAY2_HOME%/framework folder

You can add a javagent or tweak other JVM settings used by SBT/Play2 by adjusting the parameters defined there. This is probably what the clever people at Heroku has already done.

Sikora answered 3/8, 2012 at 7:25 Comment(0)
S
2

There is no clean way to pass the -javaagent parameter to the java command invocation with play 2.0.1-2.0.4 without modifying a script.

I was able to get a javaagent working using the following technique:

# Modify the play/framework/build script to include an extra environment variable
sed -i 's/^java\( \${PLAY_OPTS}\)\?/java ${PLAY_OPTS}/' ${playPath}/framework/build

Then it is possible to pass the -javaagent param like this:

export PLAY_OPTS='-javaagent:/lib/newrelic/newrelic.jar'

${playPath}/play -Dconfig.file=conf/prod.conf -Dlogger.file=conf/prod-logger.xml start


Update

An unfortunate sidenote- I just found out from New-Relic support that New-Relic definitely does not support play-framework 2.x right now (2012-10-04).


Sadowski answered 4/10, 2012 at 20:32 Comment(0)
S
1

The reason why the examples don't work, is because the examples are for Play 1.x, and you are using play 2.x. Play 1.x uses Java (via python scripts) where as Play 2 uses SBT.

You need to configure SBT. I am not an SBT expert, but from Googling, I would have thought simply running

play -javaagent:/path/to/agent.jar

and then followed by run once the console had started should do the trick, but if that doesn't work, then it is a case of finding out how to add the javaagent syntax to the SBT console.

Seaden answered 13/6, 2012 at 11:23 Comment(1)
I've already tried play -javaagent followed by run on the console without luck. I agree that the solution probably lies in passing an appropriate parameter to SBT but google isn't helping me here :(Tempura

© 2022 - 2024 — McMap. All rights reserved.