RubyFlow The Ruby and Rails community linklog

Tracking All Paper Trail Version From A Single Request With Correlation UUIDs

If you’ve ever had a need to implement an audit log to track all the changes that get persisted for all or at least some models in your application, there is a good chance that you’ve encountered PaperTrail gem that makes it trivial to track all the changes - it might be as easy as adding has_paper_trail to the desired models.

However, storing versions is just one thing. The other one is using them later, which sometimes might be far from obvious. For example, you see that some record was updated, but you don’t exactly know why. Maybe you have whodunnit stored, but it still doesn’t give you the entire picture as there might be multiple ways how a given record can be updated and you are trying to establish some causality between multiple actions as one update can lead to another one that can lead to yet another one. Not to mention that the persistence can be executed from the background jobs, which will mean that whodunnit will either be nil or be something else (if you, for example, decide to use the name of the job class for paper_trail_user). Merely using created_at won’t be that useful for sure as it’s not enough to group versions form the same context.

Fortunately, there is an easy solution to this problem, which is also quite simple to implement - it’s adding a correlation UUID.

Read more

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in