This is the first in a series of blog posts that go into detail about a number of open source projects I have released, starting with spt-development-cid. spt-development-cid is a very simple library that utilises ThreadLocal for tracking a correlation ID similar to that described by Sam Newman, in Chapter 8 of his excellent book Building Microservices. If you have ever tried to support a system consisting of multiple services that doesn’t use correlation IDs, then you will understand their importance! Sam’s book describes the concept better than I would, so I urge you to read that if you require a deeper understanding.

The code in this library is not complicated and nothing that the average reader wouldn’t be able to write themselves, however it is code that I have ended up copy/pasting on multiple projects and serves as the initial building block for the other projects I have open sourced.

The project is available in Maven Central, so to use, add it as a dependency to your project,

Then inititialise with the set method and call get to include the correlation ID in all your log statements.

You are most likely to call CorrelationId.set() when you receive a new REST API request or process a new JMS message, as such I have open sourced projects for integrating spt-development-cid into a web project and a Spring JMS (listener) project.