clj-otel

chamo92 2024-06-27T21:55:35.929799Z

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?

steffan 2024-06-27T22:23:30.234999Z

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.

steffan 2024-06-27T22:27:02.505539Z

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.

steffan 2024-06-27T22:33:15.599969Z

If you are writing purely synchronous Clojure code, you should use only https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/concepts#_current_context.

chamo92 2024-06-27T22:43:02.506799Z

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.

steffan 2024-06-27T22:49:31.928729Z

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.

chamo92 2024-06-27T22:53:43.570859Z

That makes sense. Thanks!

🙇🏼 1
steffan 2024-06-27T22:57:08.397779Z

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