Fork me on GitHub
#clj-otel
<
2024-06-27
>
chamo9221:06:35

Hi all. We are trying to understand the use case between using a bound context and a regular context. From what we are seeing: • with-span! and async-span! both set the current span of the underlying OTEL library. • with-bound-span! and async-bound-span! both set the dynamic variable. I'm seeing lots of references to async with the bound context as reasons to use it. What are some use cases for using the bound context over the regular context? Why would we use one over the other?

steffan22:06:30

As mentioned in https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/concepts#_instrumenting_asynchronous_clojure_code, you may choose to work with either bound or explicit context values when writing async Clojure code. Bound context is more convenient, as it is the default for many clj-otel functions. Explicit context is more cumbersome, as it requires passing in as a parameter to those same functions.

steffan22:06:02

Earlier releases of clj-otel did not have the concept of bound context. Several users suggested they would prefer explicit context to be managed as a dynamic var instead. Prompted by this feedback, the bound context concept was added to clj-otel as an opt-in feature.

chamo9222:06:02

Thank you. That helps. For the with-bound-span! macro, the body is meant to provide a synchronous result. For that case, is it for cases where the body returns synchronously, but has async behavior in the call? The async-bound-span! makes a lot of sense with those references. I apologize if these are getting more into the nature of async behavior in Clojure, which I'm not as familiar with.

steffan22:06:31

with-bound-span! would be used in programs working with bound context. with-bound-span! would be used to wrap a synchronous block of code. Async code would be in some other part of the same program, just not in this block.

chamo9222:06:43

That makes sense. Thanks!

1
steffan22:06:08

Putting spans around async code is tricky. The microservices examples illustrate their use, based on core.async.