Package io.opentelemetry.context
Interface ImplicitContextKeyed
-
public interface ImplicitContextKeyed
A value that can be stored insideContext
. Types will generally use this interface to allow storing themselves inContext
without exposing aContextKey
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Scope
makeCurrent()
Adds thisImplicitContextKeyed
value to thecurrent context
and makes the newContext
the current context.Context
storeInContext(Context context)
-
-
-
Method Detail
-
makeCurrent
@MustBeClosed default Scope makeCurrent()
Adds thisImplicitContextKeyed
value to thecurrent context
and makes the newContext
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 callScope.close()
automatically.This method is equivalent to
Context.current().with(value).makeCurrent()
.The default implementation of this method will store the
ImplicitContextKeyed
in aThreadLocal
. Kotlin coroutine users SHOULD NOT use this method as theThreadLocal
will not be properly synced across coroutine suspension and resumption. Instead, usewithContext(value.asContextElement())
provided by theopentelemetry-extension-kotlin
library.
-
storeInContext
Context storeInContext(Context context)
Returns a newContext
created by settingthis
into the providedContext
. It is generally recommended to callContext.with(ImplicitContextKeyed)
instead of this method. The following are equivalent.context.with(myContextValue)
myContextValue.storeInContext(context)
-
-