Story #4689

Updated by bmbouter about 4 years ago

## Motivation 

 Pulp as a multi-process system needs to make debugging easy. Currently it is hard to: 

 1. Identify which log statements are related to a specific API request 
 2. Filter out all of those that aren't 
 3. Do this across multiple processes 

 Additionally, there is a use case where an external system wants to provide the correlation id, e.g. Katello wants to submit the correlation ID as part of the request. 

 ## Solution 

 Use [django-cid]( by default, and document that it's available for users to use. 

 ## Implementation 

 ### Enabling in Pulp itself 

 1. Add django-cid as an installed app 
 2. Reconfigure the default Django logger config in []( to incorporate the CID 
 3. Add user documentation identifying the types of things they can additionally configure 
 4. Add a test to assert Pulp viewset logs contain an autogenerated CID 

 ### Enabling in the App 

 1. Add a test to assert content app logs contain an autogenerated CID 

 ### Enabling in Tasking System 

 1. *Dispatching the CID without the caller being involved:*    Have the [`_queue_reserved_task`]( [`enqueue_with_reservation`]( method expect add a new key kwarg named `_pulp_logging_cid` `_pulp_logging_cid`. All tasks shall have this added in the existing `inner_kwargs` as an additional kwarg. The [`enqueue_with_reservation`]( method will transparently add value of the `_pulp_logging_cid` in the existing `inner_kwargs` kwarg. `enqueue_with_reservation` kwarg should get the value of `_pulp_logging_cid` be gotten at dispatch time using [`get_cid`]( 

 2. *Have the CID log on the resource manager itself:*    Have the [`_queue_reserved_task`]( method call [`set_cid()`]( with the value of the new `_pulp_logging_cid` key in the existing `inner_kwargs` kwargs. kwarg _pulp_logging_cid. This will enable the correlation ID in the resource_manager logs for that task also. 

 3. *Have all tasks also use the CID:*    Have the [`perform_job`]( call [`set_cid()`]( with the value of the `_pulp_logging_cid` kwarg. kwarg _pulp_logging_cid. Then since we don't want to actually pass it to the RQ task itself, pop it off of the kwargs for the task. This will enable the correlation ID in all pulp task logs without them having to change their signatures. also.