Package io.opentelemetry.context
Interface ContextKey<T>
-
public interface ContextKey<T>Key for indexing values of typeContextKeystored in aContext.ContextKeyare compared by reference, so it is expected that only oneContextKeyis created for a particular type of context value.public class ContextUser { private static final ContextKey<MyState> KEY = ContextKey.named("MyState"); public Context startWork() { return Context.withValues(KEY, new MyState()); } public void continueWork(Context context) { MyState state = context.getValue(KEY); // Keys are compared by reference only. assert state != Context.current().getValue(ContextKey.named("MyState")); ... } }
-
-
Method Summary
Static Methods Modifier and Type Method Description static <T> ContextKey<T>named(String name)Returns a newContextKeywith the given debug name.
-
-
-
Method Detail
-
named
static <T> ContextKey<T> named(String name)
Returns a newContextKeywith the given debug name. The name does not impact behavior and is only for debugging purposes. Multiple different keys with the same name will be separate keys.
-
-