Skip to content

Commit

Permalink
append MDC keys, even if the MDC is empty. Fixes kamon-io#1225 (kamon…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantopo committed Nov 15, 2022
1 parent 92f2e3a commit e10cba2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ object ContextToMdcPropertyMapAppender {
def appendContext(mdc: java.util.Map[String, String]): java.util.Map[String, String] = {
val settings = LogbackInstrumentation.settings()

if (settings.propagateContextToMDC && mdc != null) {
if (settings.propagateContextToMDC) {
val currentContext = Kamon.currentContext()
val span = currentContext.get(Span.Key)
val mdcWithKamonContext = new util.HashMap[String, String](mdc)
val mdcWithKamonContext = {
if(mdc == null)
new util.HashMap[String, String]()
else
new util.HashMap[String, String](mdc)
}

if (span.trace.id != Identifier.Empty) {
mdcWithKamonContext.put(settings.mdcTraceIdKey, span.trace.id.string)
Expand Down

0 comments on commit e10cba2

Please sign in to comment.