Open KodrAus opened 7 years ago
Not having context threaded through the client is starting to hinder the design enough that I think I'll need to sort this out.
I think the best approach right now would be to use a framework like slog
and thread a logger around that may contain some state. Figuring out how to thread the logger is the next challenge, but it's better than passing arbitrary state.
I think doing this properly will probably mean refactoring the client internals to focus more on operational types that receive their application state and operational state differently. So rather than something like SniffedNodes
that owns its state and lives forever we have something like SniffedNodeState
and a type like NextSniffedNode
that takes as input the SniffedNodeState
and other operational bits, like a Logger
and Sender
for the lifetime of that operation. That means the logger can have contextual information on it that's only valid for that operation, and adding more operational dependencies becomes easier.
The thing I really want to avoid is having some kind of global Context
type that we pass around. As a random bag of state that's not going to give us much to work with in the future.
We need to figure out how to make some per-request state available throughout the various repos for logging (like a correlation id) that:
Task
, where manyTask
s are executed on a given threadTask
for operations sent across threads (like start a request on one thread that's actually sent on a different one)Ideally this shouldn't be leaky in the sense of needing to pass some context to most methods explicitly and it should be supported everywhere, or else it's basically useless.
I think this will be a bit tricky, and will need some thought. It might also be infeasible for both sync and async.