yada

tanzoniteblack 2017-11-16T19:49:07.000169Z

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?

tanzoniteblack 2017-11-16T19:50:57.000508Z

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?

mccraigmccraig 2017-11-16T20:49:46.000442Z

@tanzoniteblack that might be problematic - yada is async, and the thread that different parts of the interceptor chain execute on can change

tanzoniteblack 2017-11-16T20:50:44.000568Z

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

mccraigmccraig 2017-11-16T20:54:55.000036Z

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

mccraigmccraig 2017-11-16T20:55:45.000238Z

which appears to be only for futures

dominicm 2017-11-16T22:08:38.000285Z

There's a function in core

dominicm 2017-11-16T22:08:44.000181Z

bound-fn

dominicm 2017-11-16T22:09:23.000123Z

http://clojuredocs.org/clojure.core/bound-fn

mccraigmccraig 2017-11-16T22:47:53.000342Z

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