Top Description Methods
io.opentelemetry.context

public Interface ContextKey<T>

Known Direct Implementers
io.opentelemetry.context.DefaultContextKey
Annotations
@SuppressWarnings:InterfaceWithOnlyStatics

Key for indexing values of type T stored in a Context. ContextKey are compared by reference, so it is expected that only one ContextKey is 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.get(KEY);
    // Keys are compared by reference only.
    assert state != Context.current().get(ContextKey.named("MyState"));
    ...
  }
}

Method Summary

Modifier and TypeMethod and Description
public static <T> ContextKey<T>
named(String name)

Returns a new ContextKey with the given debug name.

Method Detail

namedback to summary
public static <T> ContextKey<T> named(String name)

Returns a new ContextKey with 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.