We're using https://github.com/ptaoussanis/timbre/ as a logging solution in a project we're building with Yada. It has a dynamic variable called *context*
that you can bind to automatically append provided additional information to a logging message. I've used this in an older style of ring
handlers by generating a UUID identifying a single API request, binding this UUID to the context, and also returning this UUID as a header in the response. That way I can always find all logging messages related to single API request to hunt down problems, without having to make the actual logging calls aware of this variable in every place they're called.
Generally when I've done this, I've just wrapped a ring middleware in binding ...
, since interceptors are just modifying the ctx
variable, I can't see an easy way to bind a dynamic variable on every single resource automatically, anyone have any suggestions on this?
To reword my specific question, to make sure it's understood: I want to bind a dynamic variable for every single API call that goes through my Yada server. How would I go about doing this?
@tanzoniteblack that might be problematic - yada is async, and the thread that different parts of the interceptor chain execute on can change
I know at least that core.async does a good job of preserving thread bindings through out go blocks, so that hasn't been an issue in the past for me. Manifold is new to me though, so not sure how that actually works out here
oh, ok - i guess it's possible that something could copy bindings from one thread to another... i just had a quick look through the manifold source and the only thing i could find which looks like that was this https://github.com/ztellman/manifold/blob/master/src/manifold/utils.clj#L30
which appears to be only for futures
There's a function in core
bound-fn
agents and futures seem to use the private fn clojure.core/binding-conveyor-fn
https://github.com/clojure/clojure/blob/010864f8ed828f8d261807b7345f1a539c5b20df/src/clj/clojure/core.clj#L1930 which doesn't reset the bindings after calling the fn