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

MDC fields not properly logged #23

Open
msche opened this issue Sep 16, 2024 · 1 comment
Open

MDC fields not properly logged #23

msche opened this issue Sep 16, 2024 · 1 comment

Comments

@msche
Copy link

msche commented Sep 16, 2024

Dear logtail team.

I think MDC fields are not properly logged due to the async approach of logtail. In my case I have a method like follows:

   try {
      MDC.put("TRACE_ID", UUID.randomUUID().toString());
      LOG.info("Do your thing");
    } finally {
      MDC.remove("TRACE_ID");
    }

Within log tail the logging event is queued and send later. At the moment of sending, the MDC field is already removed.

I made the following patch to Log tail that seems to fix the issue. At the moment of queuing the log event, I create a clone of the MDC context map so that I have the situation in the event as it was at the moment of logging.

class AsyncLogtailAppender : LogtailAppender() {

    override fun append(event: ILoggingEvent) {
        if (event is LoggingEvent) {
            event.mdcPropertyMap = MDC.getCopyOfContextMap()
        }
        super.append(event)
    }
}
@curusarn
Copy link
Contributor

Thank you for the report and the fix suggestion @msche!
I appreciate it!

I'm passing this to the team to get it fixed.

Thanks again!

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

2 participants