Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging MDC tags stopped working in 2.5.10 #1225

Closed
scheleaap opened this issue Nov 2, 2022 · 4 comments
Closed

Logging MDC tags stopped working in 2.5.10 #1225

scheleaap opened this issue Nov 2, 2022 · 4 comments

Comments

@scheleaap
Copy link

scheleaap commented Nov 2, 2022

After upgrading Kamon from 2.5.9 to 2.5.10, tags set in the Kamon context are no longer included in log messages.

At our company, we write log messages in JSON format and add information to the messages through the MDC through Kamon.
We use Kamon with logback-classic and logstash-logback-encoder.

Expected behavior

For example, we add the tag application-startup-marker to a log message when the application is starting up:

object Application extends App with StrictLogging {
  Kamon.init()
  Kamon.runWithContextTag("application-startup-marker", value = true)(logger.info("Application starting..."))
}

The log message then looks as follows (for Kamon ≤ 2.5.9):

{"@timestamp":"2022-11-02T08:42:52.879Z","level":"INFO","level_value":20000,"message":"Application starting...",
"logger_name":"foo.Application$","thread_name":"main","caller_class_name":"foo.Application$","caller_method_name":"$anonfun$new$1",
"caller_file_name":"Application.scala","caller_line_number":8,"application-startup-marker":"true"}
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Actual behavior

However, when we upgrade to 2.5.10, the tag suddenly disappears:

{"@timestamp":"2022-11-02T08:43:24.648Z","level":"INFO","level_value":20000,"message":"Application starting...",
"logger_name":"foo.Application$","thread_name":"main","caller_class_name":"foo.Application$","caller_method_name":"$anonfun$new$1",
"caller_file_name":"Application.scala","caller_line_number":8}
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Minimal example

I have created a minimal example here: https://github.com/scheleaap/kamon-issue. Run with sbt run.

If you change the line

      "io.kamon" %% "kamon-bundle" % "2.5.10",

to

      "io.kamon" %% "kamon-bundle" % "2.5.9",

in build.sbt, you will see the tag reappears.

Conclusion

This looks like a regression in Kamon 2.5.10.

When looking at the changes made for that release, I see there were changes in MDC-related code. Perhaps a bug was introduced there?

@antoine-morisseau
Copy link

Same issue here quit annoying since it stop us to use kamon above of 2.5.9 because we heavily rely on MDC for logging purpose.

ivantopo added a commit to ivantopo/Kamon that referenced this issue Nov 8, 2022
@ivantopo
Copy link
Contributor

ivantopo commented Nov 8, 2022

Hey @scheleaap, thank you so much for reporting this with a reproducible, it made it super easy to fix the problem! 🎉

Indeed, the regressing came with v2.5.10 where I rewrote a part of the instrumentation and it would basically just append things to the MDC if there was already something in the MDC. If the MDC was empty, Kamon wouldn't add anything to it 🤦

Fixed in #1227 and should be released pretty soon.

@scheleaap
Copy link
Author

scheleaap commented Nov 9, 2022

@ivantopo thank you for investigating & fixing the issue so fast, that's great! Looking forward to the next release :-)

@Dichotomia
Copy link

Hello!
Any news about a release containing the fix?

Thanks!

nvollmar added a commit to nvollmar/Kamon that referenced this issue Jan 18, 2023
ivantopo pushed a commit that referenced this issue Jan 24, 2023
* Revert "append MDC keys, even if the MDC is empty. Fixes #1225 (#1227)"

This reverts commit e10cba2.

* Revert "reorganize the logback instrumentation to avoid stack overflows, fixes #1212 (#1220)"

This reverts commit 5cf9653.

* Fixes instrumentation for Logback 1.4.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants