在Play应用程序中配置Kamon和AspectjWeaver

时间:2015-11-25 16:57:16

标签: scala playframework-2.0 aspectj sbt-aspectj

我正在尝试配置播放应用程序以使用Kamon。我使用

创建了一个新的播放应用程序
activator new kamon-play play-scala

然后我posted it on github。我在OS X 10.11.1上运行,我正在运行JDK 1.8.0_65-b17,项目配置了scala 2.11.6。我已根据instructions for configuring Play以及sbt-aspectj-runner kamon-play example对其进行了配置(据我所知)。但是当我尝试使用以下任一项运行应用程序时:

sbt run

activator run

我收到以下错误:

[ERROR] [11/25/2015 09:04:39.574] [ForkJoinPool-1-worker-9] [ModuleLoader(akka://kamon)] 

  ___                           _      ___   _    _                                 ___  ___ _            _
 / _ \                         | |    |_  | | |  | |                                |  \/  |(_)          (_)
/ /_\ \ ___  _ __    ___   ___ | |_     | | | |  | |  ___   __ _ __   __ ___  _ __  | .  . | _  ___  ___  _  _ __    __ _
|  _  |/ __|| '_ \  / _ \ / __|| __|    | | | |/\| | / _ \ / _` |\ \ / // _ \| '__| | |\/| || |/ __|/ __|| || '_ \  / _` |
| | | |\__ \| |_) ||  __/| (__ | |_ /\__/ / \  /\  /|  __/| (_| | \ V /|  __/| |    | |  | || |\__ \\__ \| || | | || (_| |
\_| |_/|___/| .__/  \___| \___| \__|\____/   \/  \/  \___| \__,_|  \_/  \___||_|    \_|  |_/|_||___/|___/|_||_| |_| \__, |
            | |                                                                                                      __/ |
            |_|                                                                                                     |___/

 It seems like your application was not started with the -javaagent:/path-to-aspectj-weaver.jar option but Kamon detected
 the following modules which require AspectJ to work properly:

      kamon-akka, kamon-scala, kamon-play

 If you need help on setting up the aspectj weaver go to http://kamon.io/introduction/get-started/ for more info. On the
 other hand, if you are sure that you do not need or do not want to use the weaver then you can disable this error message
 by changing the kamon.show-aspectj-missing-warning setting in your configuration file.

我已经尝试了以下所有方法:

  • aspectj-play-runner:run添加到plugins.sbt文件中(不编译)

  • 将javaagent参数传递给activator:

    activator -J-javaagent::~/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.5.jar

但是会导致以下错误:

Error opening zip file or JAR manifest missing : :~/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.5.jar
Error occurred during initialization of VM
agent library failed to init: instrument
  • 将javaagent参数传递给sbt:

    sbt run -Djavaagent:~/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.5.jar

也尝试了

sbt run -Djavaagent:~/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.5.jar -Daspectj-play-runner:run

更新

我想出了aspectj-play-runner:run是一个sbt任务/命令所以我试过了:

sbt
aspectj-runner:run

输出:

[WeavingURLClassLoader] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
java.lang.RuntimeException: Kamon has not been started yet. You must either explicitlt call Kamon.start(...) or enable automatic startup by adding -Dkamon.auto-start=true to your JVM options.

然后我尝试了:

sbt -Dkamon.auto-start=true
aspectj-runner:run

哪个输出:

[WeavingURLClassLoader] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
com.typesafe.config.ConfigException$IO: application.conf: java.io.IOException: resource not found on classpath: application.conf

最后,文件实际上说我应该正在运行

sbt
aspectj-play-runner:run

但命令/任务甚至无法识别。

2 个答案:

答案 0 :(得分:1)

我能够在Twitter上联系@kamonteam,这是他们的回复:

  

@dvMENTALmadness目前我们在使用akka和播放模块时有一个kamon的错误,直到下一个版本,我们希望在......周末,现在唯一的选择是移除kamon-akka模块: (

基于此,我从build.sbt和application.config中删除了对kamon-akka模块的引用,现在它正在工作。一旦我从项目中遇到问题,我将跟踪它并在问题解决后发布。与此同时,here's the commit为我“修复”了这个问题。我仍然需要akka模块才能为我提供完整的解决方案。

答案 1 :(得分:0)

一种解决方法是设置JAVA_OPTS环境变量。

export JAVA_OPTS="-javaagent:$HOME/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.10.jar"
sbt run