Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

@SuppressWarnings("deprecation")
@Immutable
final class ArrayBackedExtendedAttributes
extends ImmutableKeyValuePairs<ExtendedAttributeKey<?>, Object> implements ExtendedAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@

package io.opentelemetry.api.incubator.common;

import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey;

import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.common.ValueType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

@SuppressWarnings("deprecation")
class ArrayBackedExtendedAttributesBuilder implements ExtendedAttributesBuilder {
private final List<Object> data;

Expand Down Expand Up @@ -62,16 +54,16 @@ private void putValue(ExtendedAttributeKey<?> key, Value<?> valueObj) {
String keyName = key.getKey();
switch (valueObj.getType()) {
case STRING:
put(stringKey(keyName), ((Value<String>) valueObj).getValue());
put(ExtendedAttributeKey.stringKey(keyName), ((Value<String>) valueObj).getValue());
return;
case LONG:
put(longKey(keyName), ((Value<Long>) valueObj).getValue());
put(ExtendedAttributeKey.longKey(keyName), ((Value<Long>) valueObj).getValue());
return;
case DOUBLE:
put(doubleKey(keyName), ((Value<Double>) valueObj).getValue());
put(ExtendedAttributeKey.doubleKey(keyName), ((Value<Double>) valueObj).getValue());
return;
case BOOLEAN:
put(booleanKey(keyName), ((Value<Boolean>) valueObj).getValue());
put(ExtendedAttributeKey.booleanKey(keyName), ((Value<Boolean>) valueObj).getValue());
return;
case ARRAY:
List<Value<?>> arrayValues = (List<Value<?>>) valueObj.getValue();
Expand All @@ -82,28 +74,28 @@ private void putValue(ExtendedAttributeKey<?> key, Value<?> valueObj) {
for (Value<?> v : arrayValues) {
strings.add((String) v.getValue());
}
put(stringArrayKey(keyName), strings);
put(ExtendedAttributeKey.stringArrayKey(keyName), strings);
return;
case LONG_ARRAY:
List<Long> longs = new ArrayList<>(arrayValues.size());
for (Value<?> v : arrayValues) {
longs.add((Long) v.getValue());
}
put(longArrayKey(keyName), longs);
put(ExtendedAttributeKey.longArrayKey(keyName), longs);
return;
case DOUBLE_ARRAY:
List<Double> doubles = new ArrayList<>(arrayValues.size());
for (Value<?> v : arrayValues) {
doubles.add((Double) v.getValue());
}
put(doubleArrayKey(keyName), doubles);
put(ExtendedAttributeKey.doubleArrayKey(keyName), doubles);
return;
case BOOLEAN_ARRAY:
List<Boolean> booleans = new ArrayList<>(arrayValues.size());
for (Value<?> v : arrayValues) {
booleans.add((Boolean) v.getValue());
}
put(booleanArrayKey(keyName), booleans);
put(ExtendedAttributeKey.booleanArrayKey(keyName), booleans);
return;
case VALUE:
// Not coercible (empty, non-homogeneous, or unsupported element type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
* </ul>
*
* @param <T> The type of value that can be set with the key.
* @deprecated Use {@link AttributeKey} with {@link AttributeKey#valueKey(String)} instead.
*/
@Deprecated
@Immutable
public interface ExtendedAttributeKey<T> {
/** Returns the underlying String representation of the key. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
* hence the types of values that are allowed for {@link ExtendedAttributes}.
*
* <p>This is a superset of {@link io.opentelemetry.api.common.AttributeType},
*
* @deprecated Use {@link io.opentelemetry.api.common.AttributeType} instead.
*/
@Deprecated
public enum ExtendedAttributeType {
// Types copied AttributeType
STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
* {@link ExtendedAttributes}
* <li>{@link #get(AttributeKey)} supports reading values using standard {@link AttributeKey}
* </ul>
*
* @deprecated Use {@link Attributes} with {@link
* io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead.
*/
@Deprecated
@Immutable
public interface ExtendedAttributes {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@

package io.opentelemetry.api.incubator.common;

import static io.opentelemetry.api.incubator.common.ArrayBackedExtendedAttributesBuilder.toList;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey;
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Value;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/** A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. */
/**
* A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs.
*
* @deprecated Use {@link io.opentelemetry.api.common.AttributesBuilder} with {@link
* io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead.
*/
@Deprecated
public interface ExtendedAttributesBuilder {
/** Create the {@link ExtendedAttributes} from this. */
ExtendedAttributes build();
Expand Down Expand Up @@ -85,7 +81,7 @@ default <T> ExtendedAttributesBuilder put(AttributeKey<T> key, T value) {
* @return this Builder
*/
default ExtendedAttributesBuilder put(String key, String value) {
return put(stringKey(key), value);
return put(ExtendedAttributeKey.stringKey(key), value);
}

/**
Expand All @@ -97,7 +93,7 @@ default ExtendedAttributesBuilder put(String key, String value) {
* @return this Builder
*/
default ExtendedAttributesBuilder put(String key, long value) {
return put(longKey(key), value);
return put(ExtendedAttributeKey.longKey(key), value);
}

/**
Expand All @@ -109,7 +105,7 @@ default ExtendedAttributesBuilder put(String key, long value) {
* @return this Builder
*/
default ExtendedAttributesBuilder put(String key, double value) {
return put(doubleKey(key), value);
return put(ExtendedAttributeKey.doubleKey(key), value);
}

/**
Expand All @@ -121,7 +117,7 @@ default ExtendedAttributesBuilder put(String key, double value) {
* @return this Builder
*/
default ExtendedAttributesBuilder put(String key, boolean value) {
return put(booleanKey(key), value);
return put(ExtendedAttributeKey.booleanKey(key), value);
}

/**
Expand Down Expand Up @@ -151,7 +147,7 @@ default ExtendedAttributesBuilder put(String key, String... value) {
if (value == null) {
return this;
}
return put(stringArrayKey(key), Arrays.asList(value));
return put(ExtendedAttributeKey.stringArrayKey(key), Arrays.asList(value));
}

/**
Expand Down Expand Up @@ -179,7 +175,8 @@ default ExtendedAttributesBuilder put(String key, long... value) {
if (value == null) {
return this;
}
return put(longArrayKey(key), toList(value));
return put(
ExtendedAttributeKey.longArrayKey(key), ArrayBackedExtendedAttributesBuilder.toList(value));
}

/**
Expand All @@ -194,7 +191,9 @@ default ExtendedAttributesBuilder put(String key, double... value) {
if (value == null) {
return this;
}
return put(doubleArrayKey(key), toList(value));
return put(
ExtendedAttributeKey.doubleArrayKey(key),
ArrayBackedExtendedAttributesBuilder.toList(value));
}

/**
Expand All @@ -209,7 +208,9 @@ default ExtendedAttributesBuilder put(String key, boolean... value) {
if (value == null) {
return this;
}
return put(booleanArrayKey(key), toList(value));
return put(
ExtendedAttributeKey.booleanArrayKey(key),
ArrayBackedExtendedAttributesBuilder.toList(value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributeType;
import io.opentelemetry.api.incubator.common.ExtendedAttributeKey;
import io.opentelemetry.api.incubator.common.ExtendedAttributeType;
import io.opentelemetry.api.internal.InternalAttributeKeyImpl;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
Expand All @@ -17,16 +15,19 @@
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class InternalExtendedAttributeKeyImpl<T> implements ExtendedAttributeKey<T> {
@SuppressWarnings("deprecation")
public final class InternalExtendedAttributeKeyImpl<T>
implements io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> {

private final ExtendedAttributeType type;
private final io.opentelemetry.api.incubator.common.ExtendedAttributeType type;
private final String key;
private final int hashCode;

@Nullable private byte[] keyUtf8;
@Nullable private AttributeKey<T> attributeKey;

private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) {
private InternalExtendedAttributeKeyImpl(
io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) {
if (type == null) {
throw new NullPointerException("Null type");
}
Expand All @@ -38,13 +39,13 @@ private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key)
this.hashCode = buildHashCode(type, key);
}

public static <T> ExtendedAttributeKey<T> create(
@Nullable String key, ExtendedAttributeType type) {
public static <T> io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> create(
@Nullable String key, io.opentelemetry.api.incubator.common.ExtendedAttributeType type) {
return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : "");
}

@Override
public ExtendedAttributeType getType() {
public io.opentelemetry.api.incubator.common.ExtendedAttributeType getType() {
return type;
}

Expand Down Expand Up @@ -100,7 +101,8 @@ private int buildHashCode() {
return buildHashCode(type, key);
}

private static int buildHashCode(ExtendedAttributeType type, String key) {
private static int buildHashCode(
io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) {
int result = 1;
result *= 1000003;
result ^= type.hashCode();
Expand All @@ -110,13 +112,13 @@ private static int buildHashCode(ExtendedAttributeType type, String key) {
}

/**
* Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code
* null} if the {@link #getType()} has no equivalent {@link
* io.opentelemetry.api.common.AttributeType}.
* Return the equivalent {@link AttributeKey} for the {@link
* io.opentelemetry.api.incubator.common.ExtendedAttributeKey}, or {@code null} if the {@link
* #getType()} has no equivalent {@link io.opentelemetry.api.common.AttributeType}.
*/
@Nullable
@SuppressWarnings("deprecation") // Supporting deprecated EXTENDED_ATTRIBUTES until removed
public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extendedAttributeKey) {
public static <T> AttributeKey<T> toAttributeKey(
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> extendedAttributeKey) {
switch (extendedAttributeKey.getType()) {
case STRING:
return InternalAttributeKeyImpl.create(extendedAttributeKey.getKey(), AttributeType.STRING);
Expand Down Expand Up @@ -148,36 +150,50 @@ public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extende
"Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType());
}

/** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */
public static <T> ExtendedAttributeKey<T> toExtendedAttributeKey(AttributeKey<T> attributeKey) {
/**
* Return the equivalent {@link io.opentelemetry.api.incubator.common.ExtendedAttributeKey} for
* the {@link AttributeKey}.
*/
public static <T>
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> toExtendedAttributeKey(
AttributeKey<T> attributeKey) {
switch (attributeKey.getType()) {
case STRING:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.STRING);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING);
case BOOLEAN:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.BOOLEAN);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN);
case LONG:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.LONG);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG);
case DOUBLE:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.DOUBLE);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE);
case STRING_ARRAY:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.STRING_ARRAY);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING_ARRAY);
case BOOLEAN_ARRAY:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.BOOLEAN_ARRAY);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN_ARRAY);
case LONG_ARRAY:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.LONG_ARRAY);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG_ARRAY);
case DOUBLE_ARRAY:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.DOUBLE_ARRAY);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE_ARRAY);
case VALUE:
return InternalExtendedAttributeKeyImpl.create(
attributeKey.getKey(), ExtendedAttributeType.VALUE);
attributeKey.getKey(),
io.opentelemetry.api.incubator.common.ExtendedAttributeType.VALUE);
}
throw new IllegalArgumentException("Unrecognized attributeKey type: " + attributeKey.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.incubator.common.ExtendedAttributeKey;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

@SuppressWarnings("deprecation")
class ExtendedDefaultLogger implements ExtendedLogger {

private static final Logger INSTANCE = new ExtendedDefaultLogger();
Expand Down Expand Up @@ -52,7 +52,8 @@ public ExtendedLogRecordBuilder setException(Throwable throwable) {
}

@Override
public <T> ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey<T> key, T value) {
public <T> ExtendedLogRecordBuilder setAttribute(
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> key, T value) {
return this;
}

Expand Down
Loading
Loading