single

public static MetadataKey<T> single<T>(String label, Class<? extends T> clazz)

Creates a key for a single piece of metadata. If metadata is set more than once using this key for the same log statement, the last set value will be the one used, and other values will be ignored (although callers should never rely on this behavior).

Key instances behave like singletons, and two key instances with the same label will still be considered distinct. The recommended approach is to always assign MetadataKey instances to static final constants.

When calling from Kotlin, please give preference to MetadataKeysKt.singleKey(). In Kotlin, there's no explicit difference between primitive and object classes. When compiling to JVM, it is resolved during the compilation. An accident passing of a potentially primitive class may lead to a runtime exception because metadata keys are used with generics.