My app is running on amazon SWF and I want to be able to see all the logs of a specific request using an slf4j MDC. For some code flows I see the MDC in the logs, but for some they are missing, for example: I have these 2 lines of code one after the other:
MDC.put(Constants.MDC_TRACE_ID, activityInput.getWorkflowId()); log.info("Starting workflow: {}", activityInput);
I See the log, and I see the activity input has a value in the workflow id, but the log is missing the MDC, and the rest of the logs in this code path are all without the MDC.
I don’t think my log template or MDC configuration are the issue, because on most cases I do see the MDC in the logs, just here it’s missing.
Advertisement
Answer
The issue coming from 2 things I wasn’t aware of:
- I changed the MDC key to use
TraceId
instead of the defaultRequestId
and there is a framework we are using that uses the defaultRequestId
in the background. - I changed the log template, but different parts of the code uses different templates, and I missed one.
This code was still using the template with RequestId
and when my code put a string in the TraceId key, it didn’t change the value of the relevant key and the MDC was still using the value from the underlaying framework.