io.opentelemetry.api.common.AttributeKey Maven / Gradle / Ivy
Show all versions of polaris-all Show documentation
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.api.common;
import io.opentelemetry.api.internal.InternalAttributeKeyImpl;
import java.util.List;
import javax.annotation.concurrent.Immutable;
/**
* This interface provides a handle for setting the values of {@link Attributes}. The type of value
* that can be set with an implementation of this key is denoted by the type parameter.
*
* Implementations MUST be immutable, as these are used as the keys to Maps.
*
* @param The type of value that can be set with the key.
*/
@SuppressWarnings("rawtypes")
@Immutable
public interface AttributeKey {
/** Returns the underlying String representation of the key. */
String getKey();
/** Returns the type of attribute for this key. Useful for building switch statements. */
AttributeType getType();
/** Returns a new AttributeKey for String valued attributes. */
static AttributeKey stringKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.STRING);
}
/** Returns a new AttributeKey for Boolean valued attributes. */
static AttributeKey booleanKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.BOOLEAN);
}
/** Returns a new AttributeKey for Long valued attributes. */
static AttributeKey longKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.LONG);
}
/** Returns a new AttributeKey for Double valued attributes. */
static AttributeKey doubleKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE);
}
/** Returns a new AttributeKey for List<String> valued attributes. */
static AttributeKey> stringArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.STRING_ARRAY);
}
/** Returns a new AttributeKey for List<Boolean> valued attributes. */
static AttributeKey> booleanArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.BOOLEAN_ARRAY);
}
/** Returns a new AttributeKey for List<Long> valued attributes. */
static AttributeKey> longArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.LONG_ARRAY);
}
/** Returns a new AttributeKey for List<Double> valued attributes. */
static AttributeKey> doubleArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE_ARRAY);
}
}