Package io.opentelemetry.context
Interface ImplicitContextKeyed
-
public interface ImplicitContextKeyedA value that can be stored insideContext. Types will generally use this interface to allow storing themselves inContextwithout exposing aContextKey.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ScopemakeCurrent()Adds thisImplicitContextKeyedvalue to thecurrent contextand makes the newContextthe current context.ContextstoreInContext(Context context)
-
-
-
Method Detail
-
makeCurrent
@MustBeClosed default Scope 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
Context storeInContext(Context context)
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)
-
-