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 ScopeAdds thisImplicitContextKeyedvalue to thecurrent contextand makes the newContextthe current context.storeInContext(Context context)
-
Method Details
-
makeCurrent
Adds thisImplicitContextKeyedvalue to thecurrent contextand makes the newContextthe 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
ImplicitContextKeyedin aThreadLocal. Kotlin coroutine users SHOULD NOT use this method as theThreadLocalwill not be properly synced across coroutine suspension and resumption. Instead, usewithContext(value.asContextElement())provided by theopentelemetry-extension-kotlinlibrary. -
storeInContext
Returns a newContextcreated by settingthisinto the providedContext. It is generally recommended to callContext.with(ImplicitContextKeyed)instead of this method. The following are equivalent.context.with(myContextValue)myContextValue.storeInContext(context)
-