diff options
author | Diego <diegolparra@gmail.com> | 2014-11-19 22:09:41 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-11-19 22:09:41 -0300 |
commit | c03a0c5dd2a490d4b4ccbde58d18ceccc1867b44 (patch) | |
tree | 4030df619b2035db49f9b10e3c8396199f154904 /kamon-play/src/main/scala | |
parent | f6805411bbe80544d90736d560322fa6d6bd24e1 (diff) | |
download | Kamon-c03a0c5dd2a490d4b4ccbde58d18ceccc1867b44.tar.gz Kamon-c03a0c5dd2a490d4b4ccbde58d18ceccc1867b44.tar.bz2 Kamon-c03a0c5dd2a490d4b4ccbde58d18ceccc1867b44.zip |
+ core: refactor MDC facilities and closes #100
Diffstat (limited to 'kamon-play/src/main/scala')
-rw-r--r-- | kamon-play/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala | 43 |
1 files changed, 5 insertions, 38 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala b/kamon-play/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala index e2ffd3f9..3c79fae4 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala @@ -15,19 +15,12 @@ package kamon.play.instrumentation -import kamon.trace._ +import kamon.trace.logging.MdcKeysSupport import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ -import org.slf4j.MDC -import play.api.LoggerLike @Aspect -class LoggerLikeInstrumentation { - - import kamon.play.instrumentation.LoggerLikeInstrumentation._ - - @DeclareMixin("play.api.LoggerLike+") - def mixinContextAwareToLoggerLike: TraceContextAware = TraceContextAware.default +class LoggerLikeInstrumentation extends MdcKeysSupport { @Pointcut("execution(* play.api.LoggerLike+.info(..))") def infoPointcut(): Unit = {} @@ -41,35 +34,9 @@ class LoggerLikeInstrumentation { @Pointcut("execution(* play.api.LoggerLike+.trace(..))") def tracePointcut(): Unit = {} - @Around("(infoPointcut() || warnPointcut() || errorPointcut() || tracePointcut()) && this(logger)") - def aroundLog(pjp: ProceedingJoinPoint, logger: LoggerLike): Any = { - withMDC { - pjp.proceed() - } - } -} - -object LoggerLikeInstrumentation { - - @inline final def withMDC[A](block: ⇒ A): A = { - val keys = putAndExtractKeys(extractProperties(TraceRecorder.currentContext)) - - try block finally keys.foreach(k ⇒ MDC.remove(k)) - } - - def putAndExtractKeys(values: Iterable[Map[String, Any]]): Iterable[String] = values.map { - value ⇒ value.map { case (key, value) ⇒ MDC.put(key, value.toString); key } - }.flatten - - def extractProperties(traceContext: TraceContext): Iterable[Map[String, Any]] = traceContext match { - case ctx: DefaultTraceContext ⇒ - ctx.traceLocalStorage.underlyingStorage.values.collect { - case traceLocalValue @ (p: Product) ⇒ { - val properties = p.productIterator - traceLocalValue.getClass.getDeclaredFields.filter(field ⇒ field.getName != "$outer").map(_.getName -> properties.next).toMap - } - } - case EmptyTraceContext ⇒ Iterable.empty[Map[String, Any]] + @Around("(infoPointcut() || warnPointcut() || errorPointcut() || tracePointcut())") + def aroundLog(pjp: ProceedingJoinPoint): Any = withMdc { + pjp.proceed() } } |