diff options
author | Diego Parra <diegolparra@gmail.com> | 2016-07-03 15:07:03 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-03 15:07:03 -0300 |
commit | ebc560f24154ddec862411b82a79033164bb2c31 (patch) | |
tree | dd12aad175583349f160c4b960b3fdfadedcc68c /kamon-core/src/main/scala/kamon/trace | |
parent | 8516613ad2ffd5b29f2e611a0a9e9006c5613ea4 (diff) | |
parent | 8e7f64134c6e2ef48926bf63943fa3338636a62c (diff) | |
download | Kamon-ebc560f24154ddec862411b82a79033164bb2c31.tar.gz Kamon-ebc560f24154ddec862411b82a79033164bb2c31.tar.bz2 Kamon-ebc560f24154ddec862411b82a79033164bb2c31.zip |
Merge pull request #363 from dspasojevic/mdc
= kamon-core: add context name and token to MDC
Diffstat (limited to 'kamon-core/src/main/scala/kamon/trace')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/logging/MdcKeysSupport.scala | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/logging/MdcKeysSupport.scala b/kamon-core/src/main/scala/kamon/trace/logging/MdcKeysSupport.scala index abe56cd3..60a02ef8 100644 --- a/kamon-core/src/main/scala/kamon/trace/logging/MdcKeysSupport.scala +++ b/kamon-core/src/main/scala/kamon/trace/logging/MdcKeysSupport.scala @@ -17,13 +17,18 @@ package kamon.trace.logging import kamon.trace.TraceLocal.AvailableToMdc -import kamon.trace.{ Tracer, EmptyTraceContext, MetricsOnlyContext, TraceContext } +import kamon.trace.{ EmptyTraceContext, MetricsOnlyContext, TraceContext, Tracer } import kamon.util.Supplier - import org.slf4j.MDC trait MdcKeysSupport { + val traceTokenKey = "traceToken" + + val traceNameKey = "traceName" + + private val defaultKeys = Seq(traceTokenKey, traceNameKey) + def withMdc[A](thunk: ⇒ A): A = { val keys = copyToMdc(Tracer.currentContext) try thunk finally keys.foreach(key ⇒ MDC.remove(key)) @@ -34,7 +39,12 @@ trait MdcKeysSupport { private[this] def copyToMdc(traceContext: TraceContext): Iterable[String] = traceContext match { case ctx: MetricsOnlyContext ⇒ - ctx.traceLocalStorage.underlyingStorage.collect { + + // Add the default key value pairs for the trace token and trace name. + MDC.put(traceTokenKey, ctx.token) + MDC.put(traceNameKey, ctx.name) + + defaultKeys ++ ctx.traceLocalStorage.underlyingStorage.collect { case (available: AvailableToMdc, value) ⇒ Map(available.mdcKey -> String.valueOf(value)) }.map { value ⇒ value.map { case (k, v) ⇒ MDC.put(k, v); k } }.flatten |