Logging Correlation Id in Zeebe Job Worker

We’re running a self-managed Camunda 8 platform and use the Spring Zeebe client (8.4.0). We’re trying to implement a correlation Id in our log statements using the SLF4J MDC implementation.

We’re using the AspectJ “Before” advice annotation so we can intercept required variables from ActivatedJob and add to MDC. We then use “After” advice to clear the MDC:

@Before("@annotation(jobWorker)")
public void logBefore(JoinPoint joinPoint, JobWorker jobWorker) {
    var activatedJob = (ActivatedJob) joinPoint.getArgs()[0];
    MDC.put("processInstanceId" , String.valueOf(activatedJob.getProcessInstanceKey()));
}

@After("@annotation(jobWorker)")
    public void logAfter(JobWorker jobWorker) {
        MDC.clear();
}

Our pattern in the logback configuration contains the parameter %X{processInstanceId} to include this in all logs for a particular Job.

We’re finding in some scenarios the Process Instance Id in log entries for one Job are getting overwritten by another. We can tell because the details in the log entry don’t match the Process Instance Id coming from MDC.I have a suspicion the Zeebe client is using a thread pool which may be causing this.

Has anyone seen this and got advice on how to use MDC to include correlation Id in logging?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.