diff options
author | Diego <diegolparra@gmail.com> | 2014-11-07 01:36:17 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-11-07 01:36:17 -0300 |
commit | 17c558adbbf877b502acf3c3fbea4b2c9c5d0a51 (patch) | |
tree | bfc4957db57b035da7208e2169e7870ba98e4fa7 /kamon-newrelic/src/main/scala/kamon/newrelic | |
parent | 6e3d9ae88ecce10420eeac82294c54c1b43dedf4 (diff) | |
download | Kamon-17c558adbbf877b502acf3c3fbea4b2c9c5d0a51.tar.gz Kamon-17c558adbbf877b502acf3c3fbea4b2c9c5d0a51.tar.bz2 Kamon-17c558adbbf877b502acf3c3fbea4b2c9c5d0a51.zip |
+ newrelic: Report NewRelic error with correct URI and closes #103
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon/newrelic')
-rw-r--r-- | kamon-newrelic/src/main/scala/kamon/newrelic/NewRelicErrorLogger.scala | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelicErrorLogger.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelicErrorLogger.scala index 08b5df99..08fdc8c4 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelicErrorLogger.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelicErrorLogger.scala @@ -16,13 +16,21 @@ package kamon.newrelic +import java.util + import akka.actor.{ Actor, ActorLogging } import akka.event.Logging.{ Error, InitializeLogger, LoggerInitialized } import com.newrelic.api.agent.{ NewRelic ⇒ NR } -import kamon.trace.TraceContextAware +import kamon.trace.{ TraceRecorder, TraceContextAware } + +trait CustomParamsSupport { + this: NewRelicErrorLogger ⇒ + + def customParams: Map[String, String] +} -class NewRelicErrorLogger extends Actor with ActorLogging { - var aspectJMissingAlreadyReported = false +class NewRelicErrorLogger extends Actor with ActorLogging with CustomParamsSupport { + override def customParams: Map[String, String] = Map.empty def receive = { case InitializeLogger(_) ⇒ sender ! LoggerInitialized @@ -30,17 +38,21 @@ class NewRelicErrorLogger extends Actor with ActorLogging { case anythingElse ⇒ } - def notifyError(error: Error): Unit = { - val params = new java.util.HashMap[String, String]() - + def notifyError(error: Error): Unit = runInFakeTransaction { + val params = new util.HashMap[String, String]() val ctx = error.asInstanceOf[TraceContextAware].traceContext - params.put("TraceToken", ctx.token) - if (error.cause == Error.NoCause) { - NR.noticeError(error.message.toString, params) - } else { - NR.noticeError(error.cause, params) - } + params put ("TraceToken", ctx.token) + customParams foreach { case (k, v) ⇒ params.put(k, v) } + if (error.cause == Error.NoCause) NR.noticeError(error.message.toString, params) + else NR.noticeError(error.cause, params) } -} + + //Really ugly, but temporal hack until next release... + def runInFakeTransaction[T](thunk: ⇒ T): T = { + val oldName = Thread.currentThread.getName + Thread.currentThread.setName(TraceRecorder.currentContext.name) + try thunk finally Thread.currentThread.setName(oldName) + } +}
\ No newline at end of file |