Remove ReadableAttributes (#2187)

* Remove ReadableAttributes

* Don't rewrite history

* Drift
This commit is contained in:
Anuraag Agrawal 2020-12-04 04:26:24 +09:00 committed by GitHub
parent cd1f882ed2
commit 4762c6a25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 134 additions and 160 deletions

View File

@ -91,7 +91,7 @@ class ArrayBackedAttributesBuilder implements AttributesBuilder {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public AttributesBuilder putAll(ReadableAttributes attributes) {
public AttributesBuilder putAll(Attributes attributes) {
// Attributes must iterate over their entries with matching types for key / value, so this
// downcast to the raw type is safe.
attributes.forEach((key, value) -> put((AttributeKey) key, value));

View File

@ -7,6 +7,7 @@ package io.opentelemetry.api.common;
import static io.opentelemetry.api.common.ArrayBackedAttributes.sortAndFilterToAttributes;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.annotation.concurrent.Immutable;
@ -29,14 +30,23 @@ import javax.annotation.concurrent.Immutable;
*/
@SuppressWarnings("rawtypes")
@Immutable
public interface Attributes extends ReadableAttributes {
public interface Attributes {
@Override
/** Returns the value for the given {@link AttributeKey}, or {@code null} if not found. */
<T> T get(AttributeKey<T> key);
@Override
/** Iterates over all the key-value pairs of attributes contained by this instance. */
void forEach(BiConsumer<AttributeKey<?>, Object> consumer);
/** The number of attributes contained in this. */
int size();
/** Whether there are any attributes contained in this. */
boolean isEmpty();
/** Returns a read-only view of this {@link Attributes} as a {@link Map}. */
Map<AttributeKey<?>, Object> asMap();
/** Returns a {@link Attributes} instance with no attributes. */
static Attributes empty() {
return ArrayBackedAttributes.EMPTY;
@ -139,8 +149,13 @@ public interface Attributes extends ReadableAttributes {
return new ArrayBackedAttributesBuilder();
}
/** Returns a new {@link AttributesBuilder} instance from ReadableAttributes. */
static AttributesBuilder builder(ReadableAttributes attributes) {
/**
* Returns a new {@link AttributesBuilder} instance from Attributes.
*
* @deprecated Use {@link Attributes#toBuilder()}
*/
@Deprecated
static AttributesBuilder builder(Attributes attributes) {
final AttributesBuilder builder = new ArrayBackedAttributesBuilder();
builder.putAll(attributes);
return builder;

View File

@ -101,5 +101,5 @@ public interface AttributesBuilder {
*
* @return this Builder
*/
AttributesBuilder putAll(ReadableAttributes attributes);
AttributesBuilder putAll(Attributes attributes);
}

View File

@ -1,33 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.api.common;
import java.util.Map;
import java.util.function.BiConsumer;
/**
* A read-only container for String-keyed attributes.
*
* <p>See {@link Attributes} for the public API implementation.
*/
public interface ReadableAttributes {
<T> T get(AttributeKey<T> key);
/** The number of attributes contained in this. */
int size();
/** Whether there are any attributes contained in this. */
boolean isEmpty();
/** Iterates over all the key-value pairs of attributes contained by this instance. */
void forEach(BiConsumer<AttributeKey<?>, Object> consumer);
/**
* Returns a read-only view of this {@link io.opentelemetry.api.common.ReadableAttributes} as a
* {@link Map}.
*/
Map<AttributeKey<?>, Object> asMap();
}

View File

@ -237,7 +237,7 @@ class AttributesTest {
false);
assertThat(attributes).isEqualTo(wantAttributes);
AttributesBuilder newAttributes = Attributes.builder(attributes);
AttributesBuilder newAttributes = attributes.toBuilder();
newAttributes.put("newKey", "newValue");
assertThat(newAttributes.build())
.isEqualTo(

View File

@ -15,7 +15,7 @@ import io.jaegertracing.thriftjava.SpanRefType;
import io.jaegertracing.thriftjava.Tag;
import io.jaegertracing.thriftjava.TagType;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanId;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.TraceId;
@ -172,7 +172,7 @@ final class Adapter {
* @return a collection of Jaeger key values
* @see #toTag
*/
static List<Tag> toTags(ReadableAttributes attributes) {
static List<Tag> toTags(Attributes attributes) {
List<Tag> results = new ArrayList<>();
attributes.forEach((key, value) -> results.add(toTag(key, value)));
return results;

View File

@ -12,7 +12,7 @@ import com.google.gson.Gson;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Timestamps;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.exporter.jaeger.proto.api_v2.Model;
import io.opentelemetry.sdk.extension.otproto.TraceProtoUtils;
@ -181,7 +181,7 @@ final class Adapter {
* @see #toKeyValue
*/
@VisibleForTesting
static Collection<Model.KeyValue> toKeyValues(ReadableAttributes attributes) {
static Collection<Model.KeyValue> toKeyValues(Attributes attributes) {
final List<Model.KeyValue> tags = new ArrayList<>(attributes.size());
attributes.forEach((key, value) -> tags.add(toKeyValue(key, value)));
return tags;

View File

@ -10,7 +10,7 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributeType;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
@ -128,7 +128,7 @@ public final class ZipkinSpanExporter implements SpanExporter {
spanBuilder.parentId(spanData.getParentSpanId());
}
ReadableAttributes spanAttributes = spanData.getAttributes();
Attributes spanAttributes = spanData.getAttributes();
spanAttributes.forEach(
(key, value) -> spanBuilder.putTag(key.getKey(), valueToString(key, value)));
SpanData.Status status = spanData.getStatus();
@ -163,7 +163,7 @@ public final class ZipkinSpanExporter implements SpanExporter {
}
private static Endpoint chooseEndpoint(SpanData spanData, Endpoint localEndpoint) {
ReadableAttributes resourceAttributes = spanData.getResource().getAttributes();
Attributes resourceAttributes = spanData.getResource().getAttributes();
// use the service.name from the Resource, if it's been set.
String serviceNameValue = resourceAttributes.get(ResourceAttributes.SERVICE_NAME);

View File

@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.IsEqual.equalTo;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.opentracingshim.OpenTracingShim;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
@ -45,7 +45,7 @@ public final class NestedCallbacksTest {
assertThat(spans).hasSize(1);
assertThat(spans.get(0).getName()).isEqualTo("one");
ReadableAttributes attrs = spans.get(0).getAttributes();
Attributes attrs = spans.get(0).getAttributes();
assertThat(attrs.size()).isEqualTo(3);
for (int i = 1; i <= 3; i++) {
assertThat(spans.get(0).getAttributes().get(stringKey("key" + i)))

View File

@ -11,7 +11,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.sdk.resources.ResourceProvider;
import java.util.HashMap;
@ -26,7 +25,7 @@ class LambdaResourceTest {
ResourceProvider resource = new LambdaResource(emptyMap());
// when
ReadableAttributes attributes = resource.create().getAttributes();
Attributes attributes = resource.create().getAttributes();
// then
assertTrue(attributes.isEmpty());
@ -39,7 +38,7 @@ class LambdaResourceTest {
new LambdaResource(singletonMap("AWS_LAMBDA_FUNCTION_NAME", "my-function"));
// when
ReadableAttributes attributes = resource.create().getAttributes();
Attributes attributes = resource.create().getAttributes();
// then
assertThat(attributes)
@ -62,7 +61,7 @@ class LambdaResourceTest {
ResourceProvider resource = new LambdaResource(envVars);
// when
ReadableAttributes attributes = resource.create().getAttributes();
Attributes attributes = resource.create().getAttributes();
// then
assertThat(attributes)

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.extension.trace.jaeger.sampler;
import io.grpc.ManagedChannel;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.common.DaemonThreadFactory;
@ -69,7 +69,7 @@ public class JaegerRemoteSampler implements Sampler {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks) {
return sampler.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
}

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.extension.trace.jaeger.sampler;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.extension.trace.jaeger.proto.api_v2.Sampling.OperationSamplingStrategy;
@ -40,7 +40,7 @@ class PerOperationSampler implements Sampler {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks) {
Sampler sampler = this.perOperationSampler.get(name);
if (sampler == null) {

View File

@ -10,7 +10,6 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.context.Context;
@ -57,7 +56,7 @@ class RateLimitingSampler implements Sampler {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks) {
if (Span.fromContext(parentContext).getSpanContext().isSampled()) {

View File

@ -8,7 +8,6 @@ package io.opentelemetry.sdk.extension.resources;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceAttributes;
import org.junit.jupiter.api.Test;
@ -116,7 +115,7 @@ class OsResourceTest {
@Test
void inDefault() {
ReadableAttributes attributes = Resource.getDefault().getAttributes();
Attributes attributes = Resource.getDefault().getAttributes();
assertThat(attributes.get(ResourceAttributes.OS_NAME)).isNotNull();
assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION)).isNotNull();
}

View File

@ -8,7 +8,6 @@ package io.opentelemetry.sdk.extension.resources;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceAttributes;
import org.junit.jupiter.api.Test;
@ -46,7 +45,7 @@ class ProcessResourceTest {
@Test
void inDefault() {
ReadableAttributes attributes = Resource.getDefault().getAttributes();
Attributes attributes = Resource.getDefault().getAttributes();
assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isNotNull();
assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)).isNotNull();
assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)).isNotNull();

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.extension.resources;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceAttributes;
import org.junit.jupiter.api.Test;
@ -16,7 +16,7 @@ class ProcessRuntimeResourceTest {
@Test
void shouldCreateRuntimeAttributes() {
// when
ReadableAttributes attributes = new ProcessRuntimeResource().getAttributes();
Attributes attributes = new ProcessRuntimeResource().getAttributes();
// then
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotBlank();
@ -27,7 +27,7 @@ class ProcessRuntimeResourceTest {
@Test
void inDefault() {
// when
ReadableAttributes attributes = Resource.getDefault().getAttributes();
Attributes attributes = Resource.getDefault().getAttributes();
// then
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotBlank();

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.extension.incubator.trace.data;
import static java.util.Objects.requireNonNull;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceState;
@ -25,7 +25,7 @@ import java.util.List;
* <pre>{@code
* SpanDataWithClientType extends DelegatingSpanData {
*
* private final ReadableAttributes attributes;
* private final Attributes attributes;
*
* SpanDataWithClientType(SpanData delegate) {
* super(delegate);
@ -37,7 +37,7 @@ import java.util.List;
* }
*
* {@literal @}Override
* public ReadableAttributes getAttributes() {
* public Attributes getAttributes() {
* return attributes;
* }
* }
@ -103,7 +103,7 @@ public abstract class DelegatingSpanData implements SpanData {
}
@Override
public ReadableAttributes getAttributes() {
public Attributes getAttributes() {
return delegate.getAttributes();
}

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.extension.incubator.trace.data;
import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceState;
@ -144,7 +144,7 @@ public abstract class SpanDataBuilder implements SpanData {
public abstract Builder setEndEpochNanos(long epochNanos);
public abstract Builder setAttributes(ReadableAttributes attributes);
public abstract Builder setAttributes(Attributes attributes);
public abstract Builder setEvents(List<Event> events);

View File

@ -12,7 +12,6 @@ import com.google.common.testing.EqualsTester;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanId;
import io.opentelemetry.api.trace.TraceId;
@ -53,7 +52,7 @@ class DelegatingSpanDataTest {
}
@Override
public ReadableAttributes getAttributes() {
public Attributes getAttributes() {
return attributes;
}

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.extension.zpages;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Event;
@ -381,7 +381,7 @@ final class TracezZPageHandler extends ZPageHandler {
escapeHtml(renderEvent(event)));
}
private static String renderAttributes(ReadableAttributes attributes) {
private static String renderAttributes(Attributes attributes) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Attributes:{");
attributes.forEach(

View File

@ -14,7 +14,6 @@ import com.google.auto.value.extension.memoized.Memoized;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.internal.StringUtils;
import io.opentelemetry.api.internal.Utils;
import java.util.Objects;
@ -112,7 +111,7 @@ public abstract class Resource {
*
* @return a map of attributes.
*/
public abstract ReadableAttributes getAttributes();
public abstract Attributes getAttributes();
@Memoized
@Override
@ -160,7 +159,7 @@ public abstract class Resource {
return new AutoValue_Resource(attrBuilder.build());
}
private static void checkAttributes(ReadableAttributes attributes) {
private static void checkAttributes(Attributes attributes) {
attributes.forEach(
(key, value) -> {
Utils.checkArgument(

View File

@ -67,7 +67,7 @@ class EnvAutodetectResourceTest {
.readEnvironmentVariables()
.readSystemProperties()
.build();
Attributes result = (Attributes) resource.getAttributes();
Attributes result = resource.getAttributes();
assertThat(result).isEqualTo(Attributes.of(stringKey("value"), "foo"));
System.clearProperty(key);
}
@ -82,7 +82,7 @@ class EnvAutodetectResourceTest {
.readEnvironmentVariables()
.readSystemProperties()
.build();
Attributes result = (Attributes) resource.getAttributes();
Attributes result = resource.getAttributes();
assertThat(result).isEqualTo(Attributes.of(stringKey("value"), "foo"));
}
}

View File

@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.testing.EqualsTester;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.ReadableAttributes;
import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
@ -188,7 +187,7 @@ class ResourceTest {
@Test
void testSdkTelemetryResources() {
Resource resource = Resource.getTelemetrySdk();
ReadableAttributes attributes = resource.getAttributes();
Attributes attributes = resource.getAttributes();
assertThat(attributes.get(stringKey("telemetry.sdk.name"))).isEqualTo("opentelemetry");
assertThat(attributes.get(stringKey("telemetry.sdk.language"))).isEqualTo("java");
assertThat(attributes.get(stringKey("telemetry.sdk.version"))).isNotNull();

View File

@ -8,15 +8,15 @@ package io.opentelemetry.sdk.testing.assertj;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.assertj.core.api.AbstractAssert;
/** Assertions for {@link ReadableAttributes}. */
public class AttributesAssert extends AbstractAssert<AttributesAssert, ReadableAttributes> {
AttributesAssert(ReadableAttributes actual) {
/** Assertions for {@link Attributes}. */
public class AttributesAssert extends AbstractAssert<AttributesAssert, Attributes> {
AttributesAssert(Attributes actual) {
super(actual, AttributesAssert.class);
}

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.testing.assertj;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.trace.data.SpanData;
import org.assertj.core.api.Assertions;
@ -16,8 +16,8 @@ import org.assertj.core.api.Assertions;
*/
public class OpenTelemetryAssertions extends Assertions {
/** Returns an assertion for {@link ReadableAttributes}. */
public static AttributesAssert assertThat(ReadableAttributes attributes) {
/** Returns an assertion for {@link Attributes}. */
public static AttributesAssert assertThat(Attributes attributes) {
return new AttributesAssert(attributes);
}

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.testing.assertj;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
@ -193,7 +193,7 @@ public class SpanDataAssert extends AbstractAssert<SpanDataAssert, SpanData> {
}
/** Asserts the span has the given attributes. */
public SpanDataAssert hasAttributes(ReadableAttributes attributes) {
public SpanDataAssert hasAttributes(Attributes attributes) {
isNotNull();
if (!actual.getAttributes().equals(attributes)) {
failWithActualExpectedAndMessage(
@ -208,7 +208,7 @@ public class SpanDataAssert extends AbstractAssert<SpanDataAssert, SpanData> {
}
/** Asserts the span has attributes satisfying the given condition. */
public SpanDataAssert hasAttributesSatisfying(Consumer<ReadableAttributes> attributes) {
public SpanDataAssert hasAttributesSatisfying(Consumer<Attributes> attributes) {
isNotNull();
assertThat(actual.getAttributes()).as("attributes").satisfies(attributes);
return this;

View File

@ -7,7 +7,6 @@ package io.opentelemetry.sdk.testing.trace;
import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceState;
@ -153,14 +152,13 @@ public abstract class TestSpanData implements SpanData {
public abstract Builder setEndEpochNanos(long epochNanos);
/**
* Set the attributes that are associated with this span, in the form of {@link
* ReadableAttributes}.
* Set the attributes that are associated with this span, in the form of {@link Attributes}.
*
* @param attributes {@link ReadableAttributes} for this span.
* @param attributes {@link Attributes} for this span.
* @return this
* @see ReadableAttributes
* @see Attributes
*/
public abstract Builder setAttributes(ReadableAttributes attributes);
public abstract Builder setAttributes(Attributes attributes);
/**
* Set timed events that are associated with this span. Must not be null, may be empty.

View File

@ -6,7 +6,8 @@
package io.opentelemetry.sdk.trace;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@ -18,7 +19,7 @@ import java.util.function.BiConsumer;
* <p>Note: this doesn't implement the Map interface, but behaves very similarly to one.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
final class AttributesMap implements ReadableAttributes {
final class AttributesMap implements Attributes {
private final Map<AttributeKey<?>, Object> data;
private final long capacity;
@ -79,6 +80,11 @@ final class AttributesMap implements ReadableAttributes {
return Collections.unmodifiableMap(data);
}
@Override
public AttributesBuilder toBuilder() {
return Attributes.builder().putAll(this);
}
@Override
public String toString() {
return "AttributesMap{"
@ -91,7 +97,7 @@ final class AttributesMap implements ReadableAttributes {
+ '}';
}
ReadableAttributes immutableCopy() {
Attributes immutableCopy() {
Map<AttributeKey<?>, Object> dataCopy = new LinkedHashMap<>(data);
return new AttributesMap(capacity, Collections.unmodifiableMap(dataCopy));
}

View File

@ -13,7 +13,6 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.StatusCode;
@ -519,7 +518,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
}
@GuardedBy("lock")
private ReadableAttributes getImmutableAttributes() {
private Attributes getImmutableAttributes() {
if (attributes == null || attributes.isEmpty()) {
return Attributes.empty();
}

View File

@ -12,7 +12,6 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.internal.Utils;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
@ -192,7 +191,7 @@ final class SpanBuilderSdk implements SpanBuilder {
// Avoid any possibility to modify the links list by adding links to the Builder after the
// startSpan is called. If that happens all the links will be added in a new list.
links = null;
ReadableAttributes immutableAttributes = attributes == null ? Attributes.empty() : attributes;
Attributes immutableAttributes = attributes == null ? Attributes.empty() : attributes;
SamplingResult samplingResult =
traceConfig
.getSampler()
@ -208,7 +207,7 @@ final class SpanBuilderSdk implements SpanBuilder {
if (!isRecording(samplingDecision)) {
return Span.wrap(spanContext);
}
ReadableAttributes samplingAttributes = samplingResult.getAttributes();
Attributes samplingAttributes = samplingResult.getAttributes();
if (!samplingAttributes.isEmpty()) {
if (attributes == null) {
attributes = new AttributesMap(traceConfig.getMaxNumberOfAttributes());

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.trace;
import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceState;
@ -35,7 +35,7 @@ abstract class SpanWrapper implements SpanData {
abstract List<SpanData.Event> resolvedEvents();
abstract ReadableAttributes attributes();
abstract Attributes attributes();
abstract int totalAttributeCount();
@ -57,7 +57,7 @@ abstract class SpanWrapper implements SpanData {
RecordEventsReadableSpan delegate,
List<SpanData.Link> links,
List<Event> events,
ReadableAttributes attributes,
Attributes attributes,
int totalAttributeCount,
int totalRecordedEvents,
Status status,
@ -128,7 +128,7 @@ abstract class SpanWrapper implements SpanData {
}
@Override
public ReadableAttributes getAttributes() {
public Attributes getAttributes() {
return attributes();
}

View File

@ -6,7 +6,6 @@
package io.opentelemetry.sdk.trace.data;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
@ -120,7 +119,7 @@ public interface SpanData {
*
* @return the attributes recorded for this {@code Span}.
*/
ReadableAttributes getAttributes();
Attributes getAttributes();
/**
* Returns the timed events recorded for this {@code Span}.

View File

@ -5,10 +5,10 @@
package io.opentelemetry.sdk.trace.samplers;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Link;
import java.util.List;
import javax.annotation.concurrent.Immutable;
@ -22,9 +22,9 @@ enum AlwaysOffSampler implements Sampler {
Context parentContext,
String traceId,
String name,
Span.Kind spanKind,
ReadableAttributes attributes,
List<SpanData.Link> parentLinks) {
Kind spanKind,
Attributes attributes,
List<Link> parentLinks) {
return ImmutableSamplingResult.EMPTY_NOT_SAMPLED_OR_RECORDED_SAMPLING_RESULT;
}

View File

@ -5,10 +5,10 @@
package io.opentelemetry.sdk.trace.samplers;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Link;
import java.util.List;
import javax.annotation.concurrent.Immutable;
@ -22,9 +22,9 @@ enum AlwaysOnSampler implements Sampler {
Context parentContext,
String traceId,
String name,
Span.Kind spanKind,
ReadableAttributes attributes,
List<SpanData.Link> parentLinks) {
Kind spanKind,
Attributes attributes,
List<Link> parentLinks) {
return ImmutableSamplingResult.EMPTY_RECORDED_AND_SAMPLED_SAMPLING_RESULT;
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.sdk.trace.samplers;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Link;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
@ -52,9 +53,9 @@ public class ParentBasedSampler implements Sampler {
Context parentContext,
String traceId,
String name,
Span.Kind spanKind,
ReadableAttributes attributes,
List<SpanData.Link> parentLinks) {
Kind spanKind,
Attributes attributes,
List<Link> parentLinks) {
SpanContext parentSpanContext = Span.fromContext(parentContext).getSpanContext();
if (!parentSpanContext.isValid()) {
return this.root.shouldSample(

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.trace.samplers;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
@ -88,7 +88,7 @@ public interface Sampler {
* the parentContext, unless this is a root span.
* @param name the name of the new {@code Span}.
* @param spanKind the {@link Kind} of the {@code Span}.
* @param attributes {@link ReadableAttributes} associated with the span.
* @param attributes {@link Attributes} associated with the span.
* @param parentLinks the parentLinks associated with the new {@code Span}.
* @return sampling samplingResult whether span should be sampled or not.
*/
@ -97,7 +97,7 @@ public interface Sampler {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks);
/**

View File

@ -8,7 +8,6 @@ package io.opentelemetry.sdk.trace.samplers;
import static java.util.Objects.requireNonNull;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceState;
@ -17,7 +16,7 @@ import java.util.List;
/**
* Sampling result returned by {@link Sampler#shouldSample(Context, String, String, Span.Kind,
* ReadableAttributes, List)}.
* Attributes, List)}.
*/
public interface SamplingResult {
@ -96,7 +95,7 @@ public interface SamplingResult {
* @param parentTraceState The TraceState from the parent span. Might be an empty TraceState, if
* there is no parent. This will be the same TraceState that was passed in via the {@link
* SpanContext} parameter on the {@link Sampler#shouldSample(Context, String, String,
* Span.Kind, ReadableAttributes, List)} call.
* Span.Kind, Attributes, List)} call.
*/
default TraceState getUpdatedTraceState(TraceState parentTraceState) {
return parentTraceState;

View File

@ -6,11 +6,11 @@
package io.opentelemetry.sdk.trace.samplers;
import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.TraceId;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Link;
import java.util.List;
import javax.annotation.concurrent.Immutable;
@ -64,9 +64,9 @@ abstract class TraceIdRatioBasedSampler implements Sampler {
Context parentContext,
String traceId,
String name,
Span.Kind spanKind,
ReadableAttributes attributes,
List<SpanData.Link> parentLinks) {
Kind spanKind,
Attributes attributes,
List<Link> parentLinks) {
// Always sample if we are within probability range. This is true even for child spans (that
// may have had a different sampling samplingResult made) to allow for different sampling
// policies,

View File

@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
@ -44,7 +44,7 @@ class AttributesMapTest {
}
private void assertOrdering(
ReadableAttributes attributes, List<String> expectedKeyOrder, List<Long> expectedValueOrder) {
Attributes attributes, List<String> expectedKeyOrder, List<Long> expectedValueOrder) {
attributes.forEach(
new BiConsumer<AttributeKey<?>, Object>() {
private int counter = 0;

View File

@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanId;
@ -834,7 +833,7 @@ class RecordEventsReadableSpanTest {
private void verifySpanData(
SpanData spanData,
final ReadableAttributes attributes,
final Attributes attributes,
List<Event> eventData,
List<Link> links,
String spanName,
@ -857,7 +856,7 @@ class RecordEventsReadableSpanTest {
assertThat(spanData.hasEnded()).isEqualTo(hasEnded);
// verify equality manually, since the implementations don't all equals with each other.
ReadableAttributes spanDataAttributes = spanData.getAttributes();
Attributes spanDataAttributes = spanData.getAttributes();
assertThat(spanDataAttributes.size()).isEqualTo(attributes.size());
spanDataAttributes.forEach((key, value) -> assertThat(attributes.get(key)).isEqualTo(value));
}

View File

@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanBuilder;
@ -204,7 +203,7 @@ class SpanBuilderSdkTest {
RecordEventsReadableSpan span = (RecordEventsReadableSpan) spanBuilder.startSpan();
try {
SpanData spanData = span.toSpanData();
ReadableAttributes attrs = spanData.getAttributes();
Attributes attrs = spanData.getAttributes();
assertThat(attrs.size()).isEqualTo(5);
assertThat(attrs.get(stringKey("string"))).isEqualTo("value");
assertThat(attrs.get(longKey("long"))).isEqualTo(12345L);
@ -228,7 +227,7 @@ class SpanBuilderSdkTest {
RecordEventsReadableSpan span = (RecordEventsReadableSpan) spanBuilder.startSpan();
try {
ReadableAttributes attrs = span.toSpanData().getAttributes();
Attributes attrs = span.toSpanData().getAttributes();
assertThat(attrs.size()).isEqualTo(5);
assertThat(attrs.get(stringKey("string"))).isEqualTo("value");
assertThat(attrs.get(longKey("long"))).isEqualTo(12345L);
@ -245,7 +244,7 @@ class SpanBuilderSdkTest {
span.setAttribute("boolean2", true);
span.setAttribute(stringKey("stringAttribute2"), "attrvalue");
ReadableAttributes attrs = span.toSpanData().getAttributes();
Attributes attrs = span.toSpanData().getAttributes();
assertThat(attrs.size()).isEqualTo(5);
assertThat(attrs.get(stringKey("string2"))).isNull();
assertThat(attrs.get(longKey("long2"))).isNull();
@ -291,14 +290,14 @@ class SpanBuilderSdkTest {
spanBuilder.setAttribute("key2", "value2");
RecordEventsReadableSpan span = (RecordEventsReadableSpan) spanBuilder.startSpan();
ReadableAttributes beforeAttributes = span.toSpanData().getAttributes();
Attributes beforeAttributes = span.toSpanData().getAttributes();
assertThat(beforeAttributes.size()).isEqualTo(2);
assertThat(beforeAttributes.get(stringKey("key1"))).isEqualTo("value1");
assertThat(beforeAttributes.get(stringKey("key2"))).isEqualTo("value2");
spanBuilder.setAttribute("key3", "value3");
ReadableAttributes afterAttributes = span.toSpanData().getAttributes();
Attributes afterAttributes = span.toSpanData().getAttributes();
assertThat(afterAttributes.size()).isEqualTo(2);
assertThat(afterAttributes.get(stringKey("key1"))).isEqualTo("value1");
assertThat(afterAttributes.get(stringKey("key2"))).isEqualTo("value2");
@ -363,7 +362,7 @@ class SpanBuilderSdkTest {
}
RecordEventsReadableSpan span = (RecordEventsReadableSpan) spanBuilder.startSpan();
try {
ReadableAttributes attrs = span.toSpanData().getAttributes();
Attributes attrs = span.toSpanData().getAttributes();
assertThat(attrs.size()).isEqualTo(maxNumberOfAttrs);
for (int i = 0; i < maxNumberOfAttrs; i++) {
assertThat(attrs.get(longKey("key" + i))).isEqualTo(i);
@ -402,7 +401,7 @@ class SpanBuilderSdkTest {
Arrays.asList("small", null, "very large string that we have to cut"));
try {
ReadableAttributes attrs = span.toSpanData().getAttributes();
Attributes attrs = span.toSpanData().getAttributes();
assertThat(attrs.get(stringKey("builderStringNull"))).isEqualTo(null);
assertThat(attrs.get(stringKey("builderStringSmall"))).isEqualTo("small");
assertThat(attrs.get(stringKey("builderStringLarge"))).isEqualTo("very large");
@ -506,7 +505,7 @@ class SpanBuilderSdkTest {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks) {
return new SamplingResult() {
@Override
@ -554,7 +553,7 @@ class SpanBuilderSdkTest {
String traceId,
String name,
Kind spanKind,
ReadableAttributes attributes,
Attributes attributes,
List<Link> parentLinks) {
return new SamplingResult() {
@Override

View File

@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.IsEqual.equalTo;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
@ -47,7 +47,7 @@ public final class NestedCallbacksTest {
assertThat(spans).hasSize(1);
assertThat(spans.get(0).getName()).isEqualTo("one");
ReadableAttributes attrs = spans.get(0).getAttributes();
Attributes attrs = spans.get(0).getAttributes();
assertThat(attrs.size()).isEqualTo(3);
for (int i = 1; i <= 3; i++) {
assertThat(attrs.get(stringKey("key" + i))).isEqualTo(Integer.toString(i));