The main goal of this spike is to have unique traceId for each request throughout the flow of that particular request
Eg: When requesting inventory information from IMS then the flow is something like this
Controller > Handler > Repository
For the above flow many logs are generated by application, If all the logs for one particular request have same unique ID then it will help us to identify whole flow each request and pin point to issue if occurs.
In this approach we can pass unique traceId in each function where the functions are called.
Pros: This is the easiest and reliable approach
Cons: Lot of touch points, If any changes happens we have to make changes everywhere and when application grows it is very difficult to maintain
To solve the problem in first approach we can introduce global variable where traceID will be stored and can used by all the functions in the application for flow of a particular request.
Pros: Global variable is reused everywhere and no need to pass argument in each function
Cons: Global variable can be easily polluted
Example:
Since, The global variable can be easily polluted and resulting in incorrect traceID we cannot go ahead with this approach