Interface ImplicitContextKeyed


public interface ImplicitContextKeyed
A value that can be stored inside Context. Types will generally use this interface to allow storing themselves in Context without exposing a ContextKey.
  • Method Details

    • makeCurrent

      @MustBeClosed default Scope makeCurrent()
      Adds this ImplicitContextKeyed value to the current context and makes the new Context the current context. Scope.close() must be called to properly restore the previous context from before this scope of execution or context will not work correctly. It is recommended to use try-with-resources to call Scope.close() automatically.

      This method is equivalent to Context.current().with(value).makeCurrent().

      The default implementation of this method will store the ImplicitContextKeyed in a ThreadLocal. Kotlin coroutine users SHOULD NOT use this method as the ThreadLocal will not be properly synced across coroutine suspension and resumption. Instead, use withContext(value.asContextElement()) provided by the opentelemetry-extension-kotlin library.

    • storeInContext

      Context storeInContext(Context context)
      Returns a new Context created by setting this into the provided Context. It is generally recommended to call Context.with(ImplicitContextKeyed) instead of this method. The following are equivalent.
      • context.with(myContextValue)
      • myContextValue.storeInContext(context)