Similar to #4 it would be nice to create syntactic sugar that attaches a Context and then detaches it after performing an operation. Rather than using AutoCloseable it would be preferable to create a custom function on the Context interface.
Currently, this would be required to perform the operation:
fun example(ctx: Context) {
// set 'ctx' as the implicit context
val scope: Scope = ctx.attach()
// span has 'ctx' set as its parent via implicit context
tracer.createSpan("my_span")
// unset 'ctx' and restore the previous implicit context.
scope.detach()
}
Whereas I think we should aim for an API with fewer moving parts from a library consumer's perspective, similar to this:
fun example(ctx: Context) {
ctx.asImplicitContext {
tracer.createSpan("my_span")
}
}