Logger categorized by supervision subtrees

The app I’m working on is split such that the same supervision tree superstructure is duplicated for an unbounded number of “tenants” (using a :simple_one_to_one top-level supervisor). This is because I want fair scheduling and fault tolerance between tenants, but I also want multi-processing within individual tenants.

When a log is written, I’d like the tenant ID to be attached to the log. That way, if a tenant goes down, I can chase down diagnostic information for it specifically.

I could probably do this by passing the ID from parent to child, and then setting process metadata in the processes’ init function, but I don’t think other libraries would be able to pass the baton correctly when they spawn their own workers.

Is there something I’m missing here?

It looks like the pid is passed in the logger metadata, so you might be able to dynamically determine which tenant subtree is supervising the pid using a custom Logger backend and the process info

Process.info(pid)[:dictionary][:"$ancestors"]

That looks like it would work. Thanks!