Package io.opentelemetry.context
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 Summary
Modifier and TypeMethodDescriptiondefault Scope
Adds thisImplicitContextKeyed
value to thecurrent context
and makes the newContext
the current context.storeInContext
(Context context)
-
Method Details
-
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
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)
-