Fork me on GitHub
#clj-otel
<
2022-05-25
>
frank15:05:15

Does anyone have any tricks for propagating the otel contexts in ways similar to clojure dynamic bindings? (e.g. through futures and things) For example, if a span is initialized in a future, I'd like it to inherit the trace ID from the current context where the future was initialized.

steffan17:05:36

When designing clj-otel, I considered using dynamic bindings. However, I followed the https://stuartsierra.com/2013/03/29/perils-of-dynamic-scope and decided instead to make context explicit throughout. I strongly advise against it, but if you really feel you need dynamic bindings, then take a look at https://clojuredocs.org/clojure.core/bound-fn and https://clojuredocs.org/clojure.core/bound-fn* in the standard Clojure library.

steffan17:05:32

In fact, by explicitly passing in context as a parameter to your future function, there is no need for bound-fn nor bound-fn*. Use https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/CURRENT/api/steffan-westcott.clj-otel.context#current to get the current context.

frank17:05:25

I see, that helps. Thank you!