Package io.opentelemetry.context
Class ArrayBasedContext
- java.lang.Object
-
- io.opentelemetry.context.ArrayBasedContext
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ArrayBasedContext(java.lang.Object[] entries)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> V
get(ContextKey<V> key)
Returns the value stored in thisContext
for the givenContextKey
, ornull
if there is no value for the key in this context.(package private) static Context
root()
java.lang.String
toString()
<V> Context
with(ContextKey<V> key, V value)
Returns a new context with the given key value set.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.context.Context
makeCurrent, with, wrap, wrap, wrap, wrap, wrap, wrapConsumer, wrapConsumer, wrapFunction, wrapFunction, wrapSupplier
-
-
-
-
Field Detail
-
ROOT
private static final Context ROOT
-
entries
private final java.lang.Object[] entries
-
-
Method Detail
-
root
static Context root()
Description copied from interface:Context
Returns the rootContext
which all otherContext
are derived from.It should generally not be required to use the root
Context
directly - instead, useContext.current()
to operate on the currentContext
. Only use this method if you are absolutely sure you need to disregard the currentContext
- this almost always is only a workaround hiding an underlying context propagation issue.
-
get
@Nullable public <V> V get(ContextKey<V> key)
Description copied from interface:Context
Returns the value stored in thisContext
for the givenContextKey
, ornull
if there is no value for the key in this context.
-
with
public <V> Context with(ContextKey<V> key, V value)
Description copied from interface:Context
Returns a new context with the given key value set.Context withCredential = Context.current().with(CRED_KEY, cred); withCredential.wrap(new Runnable() { public void run() { readUserRecords(userId, CRED_KEY.get()); } }).run();
Note that multiple calls to
Context.with(ContextKey, Object)
can be chained together.context.with(K1, V1).with(K2, V2);
Nonetheless,
Context
should not be treated like a general purpose map with a large number of keys and values — combine multiple related items together into a single key instead of separating them. But if the items are unrelated, have separate keys for them.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-