aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-03-24 11:15:40 -0700
committerGitHub <noreply@github.com>2017-03-24 11:15:40 -0700
commita57877ba0446c0da27573a0245c16205c9f79d19 (patch)
tree5854095fbcd4f0b19db308783fc7446750b18e82 /core
parentdf6294ec87deec8d66bcadd864f59c11ff61e6f6 (diff)
downloadplatform_external_opencensus-java-a57877ba0446c0da27573a0245c16205c9f79d19.tar.gz
platform_external_opencensus-java-a57877ba0446c0da27573a0245c16205c9f79d19.tar.bz2
platform_external_opencensus-java-a57877ba0446c0da27573a0245c16205c9f79d19.zip
Rename Labels to Attributes. (#171)
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/com/google/instrumentation/trace/AttributeValue.java (renamed from core/src/main/java/com/google/instrumentation/trace/LabelValue.java)41
-rw-r--r--core/src/main/java/com/google/instrumentation/trace/Attributes.java137
-rw-r--r--core/src/main/java/com/google/instrumentation/trace/BlankSpan.java8
-rw-r--r--core/src/main/java/com/google/instrumentation/trace/Labels.java137
-rw-r--r--core/src/main/java/com/google/instrumentation/trace/Span.java12
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/AttributeValueTest.java76
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/AttributesTest.java143
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/BlankSpanTest.java6
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/LabelValueTest.java76
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/LabelsTest.java143
-rw-r--r--core/src/test/java/com/google/instrumentation/trace/SpanTest.java4
11 files changed, 393 insertions, 390 deletions
diff --git a/core/src/main/java/com/google/instrumentation/trace/LabelValue.java b/core/src/main/java/com/google/instrumentation/trace/AttributeValue.java
index 31e37a31..f5d47c75 100644
--- a/core/src/main/java/com/google/instrumentation/trace/LabelValue.java
+++ b/core/src/main/java/com/google/instrumentation/trace/AttributeValue.java
@@ -19,38 +19,39 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
- * A class that represents all the possible values for a label in {@link Labels}.. A label can have
- * 3 types of values: {@link String}, {@link Boolean} or {@link Long}.
+ * A class that represents all the possible values for an attribute in {@link Attributes}. A
+ * attribute can have 3 types of values: {@code String}, {@code Boolean} or {@code Long}.
*/
@Immutable
-public final class LabelValue {
+public final class AttributeValue {
private final String stringValue;
private final Boolean booleanValue;
private final Long longValue;
- static LabelValue stringLabelValue(String stringValue) {
- return new LabelValue(stringValue, null, null);
+ static AttributeValue stringAttributeValue(String stringValue) {
+ return new AttributeValue(stringValue, null, null);
}
- static LabelValue booleanLabelValue(boolean booleanValue) {
- return new LabelValue(null, booleanValue, null);
+ static AttributeValue booleanAttributeValue(boolean booleanValue) {
+ return new AttributeValue(null, booleanValue, null);
}
- static LabelValue longLabelValue(long longValue) {
- return new LabelValue(null, null, longValue);
+ static AttributeValue longAttributeValue(long longValue) {
+ return new AttributeValue(null, null, longValue);
}
- private LabelValue(String stringValue, Boolean booleanValue, Long longValue) {
+ private AttributeValue(
+ @Nullable String stringValue, @Nullable Boolean booleanValue, @Nullable Long longValue) {
this.stringValue = stringValue;
this.booleanValue = booleanValue;
this.longValue = longValue;
}
/**
- * Returns the {@link String} value if this is a string {@code LabelValue}, otherwise {@code
+ * Returns the {@code String} value if this is a string {@code AttributeValue}, otherwise {@code
* null}.
*
- * @return the {@link String} value if this is a string {@code LabelValue}, otherwise {@code
+ * @return the {@code String} value if this is a string {@code AttributeValue}, otherwise {@code
* null}.
*/
@Nullable
@@ -59,10 +60,10 @@ public final class LabelValue {
}
/**
- * Returns the {@link Boolean} value if this is a boolean {@code LabelValue}, otherwise {@code
+ * Returns the {@code Boolean} value if this is a boolean {@code AttributeValue}, otherwise {@code
* null}.
*
- * @return the {@link Boolean} value if this is a boolean {@code LabelValue}, otherwise {@code
+ * @return the {@code Boolean} value if this is a boolean {@code AttributeValue}, otherwise {@code
* null}.
*/
@Nullable
@@ -71,9 +72,11 @@ public final class LabelValue {
}
/**
- * Returns the {@link Long} value if this is a long {@code LabelValue}, otherwise {@code null}.
+ * Returns the {@code Long} value if this is a long {@code AttributeValue}, otherwise {@code
+ * null}.
*
- * @return the {@link Long} value if this is a long {@code LabelValue}, otherwise {@code null}.
+ * @return the {@code Long} value if this is a long {@code AttributeValue}, otherwise {@code
+ * null}.
*/
@Nullable
public Long getLongValue() {
@@ -86,11 +89,11 @@ public final class LabelValue {
return true;
}
- if (!(obj instanceof LabelValue)) {
+ if (!(obj instanceof AttributeValue)) {
return false;
}
- LabelValue that = (LabelValue) obj;
+ AttributeValue that = (AttributeValue) obj;
return Objects.equal(stringValue, that.stringValue)
&& Objects.equal(booleanValue, that.booleanValue)
&& Objects.equal(longValue, that.longValue);
@@ -120,6 +123,6 @@ public final class LabelValue {
.toString();
}
// This should never happen
- throw new RuntimeException("Not a supported label value");
+ throw new RuntimeException("Not a supported attribute value");
}
}
diff --git a/core/src/main/java/com/google/instrumentation/trace/Attributes.java b/core/src/main/java/com/google/instrumentation/trace/Attributes.java
new file mode 100644
index 00000000..4c385f20
--- /dev/null
+++ b/core/src/main/java/com/google/instrumentation/trace/Attributes.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2016, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.instrumentation.trace;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.MoreObjects;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.Immutable;
+
+/**
+ * A class that represents a set of Attributes. Each Attribute is a key-value pair, where the key is
+ * a string and the value is a {@link AttributeValue}, which can be one of String/Long/Boolean.
+ */
+@Immutable
+public final class Attributes {
+ // This object is an immutable Map.
+ private final Map<String, AttributeValue> attributes;
+
+ private Attributes(Map<String, AttributeValue> attributes) {
+ // Make attributes an immutable map.
+ this.attributes = Collections.unmodifiableMap(new HashMap<String, AttributeValue>(attributes));
+ }
+
+ /**
+ * Returns a new {@link Builder} for this class.
+ *
+ * @return a new {@code Builder} for this class.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Returns the {@link AttributeValue} associated with the key, or {@code null} if it does not
+ * exist.
+ *
+ * @param key The attribute key to lookup.
+ * @return The {@code AttributeValue} associated with the key, or {@code null} if it does not
+ * exist.
+ * @throws NullPointerException if key is {@code null}.
+ */
+ @Nullable
+ public AttributeValue getAttributeValue(String key) {
+ return attributes.get(checkNotNull(key, "key"));
+ }
+
+ /**
+ * Returns The full set of attributes as an immutable {@link Map}.
+ *
+ * @return The full set of attributes as an immutable {@code Map}.
+ */
+ public Map<String, AttributeValue> getAll() {
+ // It is safe to return the attributes directly because it is an immutable Map.
+ return attributes;
+ }
+
+ @Override
+ public String toString() {
+ MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
+ for (Map.Entry<String, AttributeValue> entry : attributes.entrySet()) {
+ toStringHelper.add(entry.getKey(), entry.getValue());
+ }
+ return toStringHelper.toString();
+ }
+
+ /** Builder class for {@link Attributes}. */
+ public static final class Builder {
+ private final Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
+
+ private Builder() {}
+
+ /**
+ * Puts an attribute with a string value. Replaces any existing attribute with the key.
+ *
+ * @param key Key to associate with the value.
+ * @param stringValue The new value.
+ * @return this.
+ * @throws NullPointerException if {@code key} or {@code stringValue} are {@code null}.
+ */
+ public Builder putStringAttribute(String key, String stringValue) {
+ attributes.put(
+ checkNotNull(key, "key"),
+ AttributeValue.stringAttributeValue(checkNotNull(stringValue, "stringValue")));
+ return this;
+ }
+
+ /**
+ * Puts an attribute with a boolean value. Replaces any existing attribute with the key.
+ *
+ * @param key Key to associate with the value.
+ * @param booleanValue The new value.
+ * @return this.
+ * @throws NullPointerException if {@code key} is {@code null}.
+ */
+ public Builder putBooleanAttribute(String key, boolean booleanValue) {
+ attributes.put(checkNotNull(key, "key"), AttributeValue.booleanAttributeValue(booleanValue));
+ return this;
+ }
+
+ /**
+ * Puts an attribute with a long value. Replaces any existing attribute with the key.
+ *
+ * @param key Key to associate with the value.
+ * @param longValue The new value.
+ * @return this.
+ * @throws NullPointerException if {@code key} is {@code null}.
+ */
+ public Builder putLongAttribute(String key, long longValue) {
+ attributes.put(checkNotNull(key, "key"), AttributeValue.longAttributeValue(longValue));
+ return this;
+ }
+
+ /**
+ * Builds and returns a {@code Attributes} with the desired values.
+ *
+ * @return a {@code Attributes} with the desired values.
+ */
+ public Attributes build() {
+ return new Attributes(attributes);
+ }
+ }
+}
diff --git a/core/src/main/java/com/google/instrumentation/trace/BlankSpan.java b/core/src/main/java/com/google/instrumentation/trace/BlankSpan.java
index 35dfc3f3..af2c8f8e 100644
--- a/core/src/main/java/com/google/instrumentation/trace/BlankSpan.java
+++ b/core/src/main/java/com/google/instrumentation/trace/BlankSpan.java
@@ -30,17 +30,17 @@ public final class BlankSpan extends Span {
super(SpanContext.INVALID, null);
}
- /** No-op implementation of the {@link Span#addLabels(Labels)} method. */
+ /** No-op implementation of the {@link Span#addAttributes(Attributes)} method. */
@Override
- public void addLabels(Labels labels) {}
+ public void addAttributes(Attributes attributes) {}
/** No-op implementation of the {@link Span#addAnnotation(String)} method. */
@Override
public void addAnnotation(String description) {}
- /** No-op implementation of the {@link Span#addAnnotation(String, Labels)} method. */
+ /** No-op implementation of the {@link Span#addAnnotation(String, Attributes)} method. */
@Override
- public void addAnnotation(String description, Labels labels) {}
+ public void addAnnotation(String description, Attributes attributes) {}
/** No-op implementation of the {@link Span#addNetworkEvent(NetworkEvent)} method. */
@Override
diff --git a/core/src/main/java/com/google/instrumentation/trace/Labels.java b/core/src/main/java/com/google/instrumentation/trace/Labels.java
deleted file mode 100644
index 4589960d..00000000
--- a/core/src/main/java/com/google/instrumentation/trace/Labels.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2016, Google Inc.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.instrumentation.trace;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.MoreObjects;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-/**
- * A class that represents a set of Labels. Each Label is a key-value pair, where the key is a
- * string and the value is a {@link LabelValue}, which can be one of String/Long/Boolean.
- *
- * @see LabelValue
- */
-@Immutable
-public final class Labels {
- // This object is an immutable Map.
- private final Map<String, LabelValue> labels;
-
- private Labels(Map<String, LabelValue> labels) {
- // Make labels an immutable map.
- this.labels = Collections.unmodifiableMap(new HashMap<String, LabelValue>(labels));
- }
-
- /**
- * Returns a new {@link Builder} for this class.
- *
- * @return a new {@code Builder} for this class.
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Returns the {@link LabelValue} associated with the key, or {@code null} if it does not exist.
- *
- * @param key The label key to lookup.
- * @return The {@code LabelValue} associated with the key, or {@code null} if it does not exist.
- * @throws NullPointerException if key is {@code null}.
- */
- @Nullable
- public LabelValue getLabelValue(String key) {
- return labels.get(checkNotNull(key, "key"));
- }
-
- /**
- * Returns The full set of labels as an immutable {@link Map}.
- *
- * @return The full set of labels as an immutable {@code Map}.
- */
- public Map<String, LabelValue> getAll() {
- // It is safe to return the labels directly because it is an immutable Map.
- return labels;
- }
-
- @Override
- public String toString() {
- MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
- for (Map.Entry<String, LabelValue> entry : labels.entrySet()) {
- toStringHelper.add(entry.getKey(), entry.getValue());
- }
- return toStringHelper.toString();
- }
-
- /** Builder class for {@link Labels}. */
- public static final class Builder {
- private final Map<String, LabelValue> labels = new HashMap<String, LabelValue>();
-
- private Builder() {}
-
- /**
- * Puts a label with a string value. Replaces any existing label with the key.
- *
- * @param key Key to associate with the value.
- * @param stringValue The new value.
- * @return this.
- * @throws NullPointerException if {@code key} or {@code stringValue} are {@code null}.
- */
- public Builder putStringLabel(String key, String stringValue) {
- labels.put(
- checkNotNull(key, "key"),
- LabelValue.stringLabelValue(checkNotNull(stringValue, "stringValue")));
- return this;
- }
-
- /**
- * Puts a label with a boolean value. Replaces any existing label with the key.
- *
- * @param key Key to associate with the value.
- * @param booleanValue The new value.
- * @return this.
- * @throws NullPointerException if {@code key} is {@code null}.
- */
- public Builder putBooleanLabel(String key, boolean booleanValue) {
- labels.put(checkNotNull(key, "key"), LabelValue.booleanLabelValue(booleanValue));
- return this;
- }
-
- /**
- * Puts a label with a long value. Replaces any existing label with the key.
- *
- * @param key Key to associate with the value.
- * @param longValue The new value.
- * @return this.
- * @throws NullPointerException if {@code key} is {@code null}.
- */
- public Builder putLongLabel(String key, long longValue) {
- labels.put(checkNotNull(key, "key"), LabelValue.longLabelValue(longValue));
- return this;
- }
-
- /**
- * Builds and returns a {@code Labels} with the desired values.
- *
- * @return a {@code Labels} with the desired values.
- */
- public Labels build() {
- return new Labels(labels);
- }
- }
-}
diff --git a/core/src/main/java/com/google/instrumentation/trace/Span.java b/core/src/main/java/com/google/instrumentation/trace/Span.java
index 28ddd732..864df8fc 100644
--- a/core/src/main/java/com/google/instrumentation/trace/Span.java
+++ b/core/src/main/java/com/google/instrumentation/trace/Span.java
@@ -71,11 +71,11 @@ public abstract class Span {
}
/**
- * Adds a set of labels to the {@code Span}.
+ * Adds a set of attributes to the {@code Span}.
*
- * @param labels The labels that will be added and associated with the {@code Span}.
+ * @param attributes The attributes that will be added and associated with the {@code Span}.
*/
- public abstract void addLabels(Labels labels);
+ public abstract void addAttributes(Attributes attributes);
/**
* Adds an annotation to the {@code Span}.
@@ -88,10 +88,10 @@ public abstract class Span {
* Adds an annotation to the {@code Span}.
*
* @param description The description of the annotation time event.
- * @param labels The labels that will be added; these are associated with this annotation, not the
- * {@code Span} as for {@link #addLabels}.
+ * @param attributes The attributes that will be added; these are associated with this annotation,
+ * not the {@code Span} as for {@link #addAttributes}.
*/
- public abstract void addAnnotation(String description, Labels labels);
+ public abstract void addAnnotation(String description, Attributes attributes);
/**
* Adds a NetworkEvent to the {@code Span}.
diff --git a/core/src/test/java/com/google/instrumentation/trace/AttributeValueTest.java b/core/src/test/java/com/google/instrumentation/trace/AttributeValueTest.java
new file mode 100644
index 00000000..337aa36e
--- /dev/null
+++ b/core/src/test/java/com/google/instrumentation/trace/AttributeValueTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.instrumentation.trace;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link AttributeValue}. */
+@RunWith(JUnit4.class)
+public class AttributeValueTest {
+ @Test
+ public void stringAttributeValue() {
+ AttributeValue attribute = AttributeValue.stringAttributeValue("MyStringAttributeValue");
+ assertThat(attribute.getStringValue()).isEqualTo("MyStringAttributeValue");
+ assertThat(attribute.getBooleanValue()).isNull();
+ assertThat(attribute.getLongValue()).isNull();
+ }
+
+ @Test
+ public void booleanAttributeValue() {
+ AttributeValue attribute = AttributeValue.booleanAttributeValue(true);
+ assertThat(attribute.getStringValue()).isNull();
+ assertThat(attribute.getBooleanValue()).isTrue();
+ assertThat(attribute.getLongValue()).isNull();
+ }
+
+ @Test
+ public void longAttributeValue() {
+ AttributeValue attribute = AttributeValue.longAttributeValue(123456L);
+ assertThat(attribute.getStringValue()).isNull();
+ assertThat(attribute.getBooleanValue()).isNull();
+ assertThat(attribute.getLongValue()).isEqualTo(123456L);
+ }
+
+ @Test
+ public void attributeValue_EqualsAndHashCode() {
+ EqualsTester tester = new EqualsTester();
+ tester.addEqualityGroup(
+ AttributeValue.stringAttributeValue("MyStringAttributeValue"),
+ AttributeValue.stringAttributeValue("MyStringAttributeValue"));
+ tester.addEqualityGroup(AttributeValue.stringAttributeValue("MyStringAttributeDiffValue"));
+ tester.addEqualityGroup(AttributeValue.booleanAttributeValue(true), AttributeValue.booleanAttributeValue(true));
+ tester.addEqualityGroup(AttributeValue.booleanAttributeValue(false));
+ tester.addEqualityGroup(AttributeValue.longAttributeValue(123456L), AttributeValue.longAttributeValue(123456L));
+ tester.addEqualityGroup(AttributeValue.longAttributeValue(1234567L));
+ tester.testEquals();
+ }
+
+ @Test
+ public void attributeValue_ToString() {
+ AttributeValue attribute = AttributeValue.stringAttributeValue("MyStringAttributeValue");
+ assertThat(attribute.toString()).contains("string");
+ assertThat(attribute.toString()).contains("MyStringAttributeValue");
+ attribute = AttributeValue.booleanAttributeValue(true);
+ assertThat(attribute.toString()).contains("boolean");
+ assertThat(attribute.toString()).contains("true");
+ attribute = AttributeValue.longAttributeValue(123456L);
+ assertThat(attribute.toString()).contains("long");
+ assertThat(attribute.toString()).contains("123456");
+ }
+}
diff --git a/core/src/test/java/com/google/instrumentation/trace/AttributesTest.java b/core/src/test/java/com/google/instrumentation/trace/AttributesTest.java
new file mode 100644
index 00000000..95dc5c73
--- /dev/null
+++ b/core/src/test/java/com/google/instrumentation/trace/AttributesTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.instrumentation.trace;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link Attributes}. */
+@RunWith(JUnit4.class)
+public class AttributesTest {
+ @Test
+ public void putStringAttribute() {
+ Attributes attributes =
+ Attributes.builder().putStringAttribute("MyStringAttributeKey", "MyStringAttributeValue").build();
+ assertThat(attributes.getAll().size()).isEqualTo(1);
+ assertThat(attributes.getAll().containsKey("MyStringAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyStringAttributeKey"))
+ .isEqualTo(AttributeValue.stringAttributeValue("MyStringAttributeValue"));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void putStringAttribute_NullKey() {
+ Attributes.builder().putStringAttribute(null, "MyStringAttributeValue").build();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void putStringAttribute_NullValue() {
+ Attributes.builder().putStringAttribute("MyStringAttributeKey", null).build();
+ }
+
+ @Test
+ public void putBooleanAttribute() {
+ Attributes attributes = Attributes.builder().putBooleanAttribute("MyBooleanAttributeKey", true).build();
+ assertThat(attributes.getAll().size()).isEqualTo(1);
+ assertThat(attributes.getAll().containsKey("MyBooleanAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyBooleanAttributeKey"))
+ .isEqualTo(AttributeValue.booleanAttributeValue(true));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void putBooleanAttribute_NullKey() {
+ Attributes.builder().putBooleanAttribute(null, true).build();
+ }
+
+ @Test
+ public void putLongAttribute() {
+ Attributes attributes = Attributes.builder().putLongAttribute("MyLongAttributeKey", 123L).build();
+ assertThat(attributes.getAll().size()).isEqualTo(1);
+ assertThat(attributes.getAll().containsKey("MyLongAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyLongAttributeKey")).isEqualTo(AttributeValue.longAttributeValue(123L));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void putLongAttribute_NullKey() {
+ Attributes.builder().putLongAttribute(null, 123L).build();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getAttributeValue_NullKey() {
+ Attributes.builder()
+ .putStringAttribute("MyStringAttributeKey", "MyStringAttributeValue")
+ .build()
+ .getAttributeValue(null);
+ }
+
+ @Test
+ public void putMultipleAttributes() {
+ Attributes attributes =
+ Attributes.builder()
+ .putStringAttribute("MyStringAttributeKey", "MyStringAttributeValue")
+ .putBooleanAttribute("MyBooleanAttributeKey", true)
+ .putLongAttribute("MyLongAttributeKey", 123L)
+ .build();
+ assertThat(attributes.getAll().size()).isEqualTo(3);
+ assertThat(attributes.getAll().containsKey("MyStringAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyStringAttributeKey"))
+ .isEqualTo(AttributeValue.stringAttributeValue("MyStringAttributeValue"));
+ assertThat(attributes.getAll().containsKey("MyBooleanAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyBooleanAttributeKey"))
+ .isEqualTo(AttributeValue.booleanAttributeValue(true));
+ assertThat(attributes.getAll().containsKey("MyLongAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyLongAttributeKey")).isEqualTo(AttributeValue.longAttributeValue(123L));
+ }
+
+ @Test
+ public void putMultipleAttribute_SameKey() {
+ Attributes attributes =
+ Attributes.builder()
+ .putStringAttribute("MyAttributeKey", "MyStringAttributeValue")
+ .putLongAttribute("MyAttributeKey", 123L)
+ .build();
+ assertThat(attributes.getAll().size()).isEqualTo(1);
+ assertThat(attributes.getAll().containsKey("MyAttributeKey")).isTrue();
+ assertThat(attributes.getAttributeValue("MyAttributeKey")).isEqualTo(AttributeValue.longAttributeValue(123L));
+ }
+
+ @Test
+ public void putMultipleAttributes_SameType() {
+ Attributes attributes =
+ Attributes.builder()
+ .putLongAttribute("MyLongAttributeKey1", 1L)
+ .putLongAttribute("MyLongAttributeKey12", 12L)
+ .putLongAttribute("MyLongAttributeKey123", 123L)
+ .build();
+ assertThat(attributes.getAll().size()).isEqualTo(3);
+ assertThat(attributes.getAll().containsKey("MyLongAttributeKey1")).isTrue();
+ assertThat(attributes.getAttributeValue("MyLongAttributeKey1")).isEqualTo(AttributeValue.longAttributeValue(1L));
+ assertThat(attributes.getAll().containsKey("MyLongAttributeKey12")).isTrue();
+ assertThat(attributes.getAttributeValue("MyLongAttributeKey12")).isEqualTo(AttributeValue.longAttributeValue(12L));
+ assertThat(attributes.getAll().containsKey("MyLongAttributeKey123")).isTrue();
+ assertThat(attributes.getAttributeValue("MyLongAttributeKey123"))
+ .isEqualTo(AttributeValue.longAttributeValue(123L));
+ }
+
+ @Test
+ public void attributes_ToString() {
+ Attributes attributes =
+ Attributes.builder().putStringAttribute("MyStringAttributeKey", "MyStringAttributeValue").build();
+ assertThat(attributes.toString()).contains("MyStringAttributeKey");
+ assertThat(attributes.toString())
+ .contains(AttributeValue.stringAttributeValue("MyStringAttributeValue").toString());
+ attributes = Attributes.builder().putBooleanAttribute("MyBooleanAttributeKey", true).build();
+ assertThat(attributes.toString()).contains("MyBooleanAttributeKey");
+ assertThat(attributes.toString()).contains(AttributeValue.booleanAttributeValue(true).toString());
+ attributes = Attributes.builder().putLongAttribute("MyLongAttributeKey", 123L).build();
+ assertThat(attributes.toString()).contains("MyLongAttributeKey");
+ assertThat(attributes.toString()).contains(AttributeValue.longAttributeValue(123L).toString());
+ }
+}
diff --git a/core/src/test/java/com/google/instrumentation/trace/BlankSpanTest.java b/core/src/test/java/com/google/instrumentation/trace/BlankSpanTest.java
index e16b2a39..19e8fea1 100644
--- a/core/src/test/java/com/google/instrumentation/trace/BlankSpanTest.java
+++ b/core/src/test/java/com/google/instrumentation/trace/BlankSpanTest.java
@@ -31,11 +31,11 @@ public class BlankSpanTest {
@Test
public void doNotCrash() {
// Tests only that all the methods are not crashing/throwing errors.
- BlankSpan.INSTANCE.addLabels(
- Labels.builder().putStringLabel("MyLabelKey", "MyLabelValue").build());
+ BlankSpan.INSTANCE.addAttributes(
+ Attributes.builder().putStringAttribute("MyAttributeKey", "MyAttributeValue").build());
BlankSpan.INSTANCE.addAnnotation("MyAnnotation");
BlankSpan.INSTANCE.addAnnotation(
- "MyAnnotation", Labels.builder().putStringLabel("MyLabelKey", "MyLabelValue").build());
+ "MyAnnotation", Attributes.builder().putStringAttribute("MyAttributeKey", "MyAttributeValue").build());
BlankSpan.INSTANCE.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build());
BlankSpan.INSTANCE.addChildLink(BlankSpan.INSTANCE);
BlankSpan.INSTANCE.end(EndSpanOptions.DEFAULT);
diff --git a/core/src/test/java/com/google/instrumentation/trace/LabelValueTest.java b/core/src/test/java/com/google/instrumentation/trace/LabelValueTest.java
deleted file mode 100644
index b929d8c5..00000000
--- a/core/src/test/java/com/google/instrumentation/trace/LabelValueTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2017, Google Inc.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.instrumentation.trace;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.testing.EqualsTester;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link LabelValue}. */
-@RunWith(JUnit4.class)
-public class LabelValueTest {
- @Test
- public void stringLabelValue() {
- LabelValue label = LabelValue.stringLabelValue("MyStringLabelValue");
- assertThat(label.getStringValue()).isEqualTo("MyStringLabelValue");
- assertThat(label.getBooleanValue()).isNull();
- assertThat(label.getLongValue()).isNull();
- }
-
- @Test
- public void booleanLabelValue() {
- LabelValue label = LabelValue.booleanLabelValue(true);
- assertThat(label.getStringValue()).isNull();
- assertThat(label.getBooleanValue()).isTrue();
- assertThat(label.getLongValue()).isNull();
- }
-
- @Test
- public void longLabelValue() {
- LabelValue label = LabelValue.longLabelValue(123456L);
- assertThat(label.getStringValue()).isNull();
- assertThat(label.getBooleanValue()).isNull();
- assertThat(label.getLongValue()).isEqualTo(123456L);
- }
-
- @Test
- public void labelValue_EqualsAndHashCode() {
- EqualsTester tester = new EqualsTester();
- tester.addEqualityGroup(
- LabelValue.stringLabelValue("MyStringLabelValue"),
- LabelValue.stringLabelValue("MyStringLabelValue"));
- tester.addEqualityGroup(LabelValue.stringLabelValue("MyStringLabelDiffValue"));
- tester.addEqualityGroup(LabelValue.booleanLabelValue(true), LabelValue.booleanLabelValue(true));
- tester.addEqualityGroup(LabelValue.booleanLabelValue(false));
- tester.addEqualityGroup(LabelValue.longLabelValue(123456L), LabelValue.longLabelValue(123456L));
- tester.addEqualityGroup(LabelValue.longLabelValue(1234567L));
- tester.testEquals();
- }
-
- @Test
- public void labelValue_ToString() {
- LabelValue label = LabelValue.stringLabelValue("MyStringLabelValue");
- assertThat(label.toString()).contains("string");
- assertThat(label.toString()).contains("MyStringLabelValue");
- label = LabelValue.booleanLabelValue(true);
- assertThat(label.toString()).contains("boolean");
- assertThat(label.toString()).contains("true");
- label = LabelValue.longLabelValue(123456L);
- assertThat(label.toString()).contains("long");
- assertThat(label.toString()).contains("123456");
- }
-}
diff --git a/core/src/test/java/com/google/instrumentation/trace/LabelsTest.java b/core/src/test/java/com/google/instrumentation/trace/LabelsTest.java
deleted file mode 100644
index dc5bd6b7..00000000
--- a/core/src/test/java/com/google/instrumentation/trace/LabelsTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2017, Google Inc.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.instrumentation.trace;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link Labels}. */
-@RunWith(JUnit4.class)
-public class LabelsTest {
- @Test
- public void putStringLabel() {
- Labels labels =
- Labels.builder().putStringLabel("MyStringLabelKey", "MyStringLabelValue").build();
- assertThat(labels.getAll().size()).isEqualTo(1);
- assertThat(labels.getAll().containsKey("MyStringLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyStringLabelKey"))
- .isEqualTo(LabelValue.stringLabelValue("MyStringLabelValue"));
- }
-
- @Test(expected = NullPointerException.class)
- public void putStringLabel_NullKey() {
- Labels.builder().putStringLabel(null, "MyStringLabelValue").build();
- }
-
- @Test(expected = NullPointerException.class)
- public void putStringLabel_NullValue() {
- Labels.builder().putStringLabel("MyStringLabelKey", null).build();
- }
-
- @Test
- public void putBooleanLabel() {
- Labels labels = Labels.builder().putBooleanLabel("MyBooleanLabelKey", true).build();
- assertThat(labels.getAll().size()).isEqualTo(1);
- assertThat(labels.getAll().containsKey("MyBooleanLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyBooleanLabelKey"))
- .isEqualTo(LabelValue.booleanLabelValue(true));
- }
-
- @Test(expected = NullPointerException.class)
- public void putBooleanLabel_NullKey() {
- Labels.builder().putBooleanLabel(null, true).build();
- }
-
- @Test
- public void putLongLabel() {
- Labels labels = Labels.builder().putLongLabel("MyLongLabelKey", 123L).build();
- assertThat(labels.getAll().size()).isEqualTo(1);
- assertThat(labels.getAll().containsKey("MyLongLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyLongLabelKey")).isEqualTo(LabelValue.longLabelValue(123L));
- }
-
- @Test(expected = NullPointerException.class)
- public void putLongLabel_NullKey() {
- Labels.builder().putLongLabel(null, 123L).build();
- }
-
- @Test(expected = NullPointerException.class)
- public void getLabelValue_NullKey() {
- Labels.builder()
- .putStringLabel("MyStringLabelKey", "MyStringLabelValue")
- .build()
- .getLabelValue(null);
- }
-
- @Test
- public void putMultipleLabels() {
- Labels labels =
- Labels.builder()
- .putStringLabel("MyStringLabelKey", "MyStringLabelValue")
- .putBooleanLabel("MyBooleanLabelKey", true)
- .putLongLabel("MyLongLabelKey", 123L)
- .build();
- assertThat(labels.getAll().size()).isEqualTo(3);
- assertThat(labels.getAll().containsKey("MyStringLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyStringLabelKey"))
- .isEqualTo(LabelValue.stringLabelValue("MyStringLabelValue"));
- assertThat(labels.getAll().containsKey("MyBooleanLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyBooleanLabelKey"))
- .isEqualTo(LabelValue.booleanLabelValue(true));
- assertThat(labels.getAll().containsKey("MyLongLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyLongLabelKey")).isEqualTo(LabelValue.longLabelValue(123L));
- }
-
- @Test
- public void putMultipleLabel_SameKey() {
- Labels labels =
- Labels.builder()
- .putStringLabel("MyLabelKey", "MyStringLabelValue")
- .putLongLabel("MyLabelKey", 123L)
- .build();
- assertThat(labels.getAll().size()).isEqualTo(1);
- assertThat(labels.getAll().containsKey("MyLabelKey")).isTrue();
- assertThat(labels.getLabelValue("MyLabelKey")).isEqualTo(LabelValue.longLabelValue(123L));
- }
-
- @Test
- public void putMultipleLabels_SameType() {
- Labels labels =
- Labels.builder()
- .putLongLabel("MyLongLabelKey1", 1L)
- .putLongLabel("MyLongLabelKey12", 12L)
- .putLongLabel("MyLongLabelKey123", 123L)
- .build();
- assertThat(labels.getAll().size()).isEqualTo(3);
- assertThat(labels.getAll().containsKey("MyLongLabelKey1")).isTrue();
- assertThat(labels.getLabelValue("MyLongLabelKey1")).isEqualTo(LabelValue.longLabelValue(1L));
- assertThat(labels.getAll().containsKey("MyLongLabelKey12")).isTrue();
- assertThat(labels.getLabelValue("MyLongLabelKey12")).isEqualTo(LabelValue.longLabelValue(12L));
- assertThat(labels.getAll().containsKey("MyLongLabelKey123")).isTrue();
- assertThat(labels.getLabelValue("MyLongLabelKey123"))
- .isEqualTo(LabelValue.longLabelValue(123L));
- }
-
- @Test
- public void labels_ToString() {
- Labels labels =
- Labels.builder().putStringLabel("MyStringLabelKey", "MyStringLabelValue").build();
- assertThat(labels.toString()).contains("MyStringLabelKey");
- assertThat(labels.toString())
- .contains(LabelValue.stringLabelValue("MyStringLabelValue").toString());
- labels = Labels.builder().putBooleanLabel("MyBooleanLabelKey", true).build();
- assertThat(labels.toString()).contains("MyBooleanLabelKey");
- assertThat(labels.toString()).contains(LabelValue.booleanLabelValue(true).toString());
- labels = Labels.builder().putLongLabel("MyLongLabelKey", 123L).build();
- assertThat(labels.toString()).contains("MyLongLabelKey");
- assertThat(labels.toString()).contains(LabelValue.longLabelValue(123L).toString());
- }
-}
diff --git a/core/src/test/java/com/google/instrumentation/trace/SpanTest.java b/core/src/test/java/com/google/instrumentation/trace/SpanTest.java
index fcbf9aac..7dfbcfe6 100644
--- a/core/src/test/java/com/google/instrumentation/trace/SpanTest.java
+++ b/core/src/test/java/com/google/instrumentation/trace/SpanTest.java
@@ -91,13 +91,13 @@ public class SpanTest {
}
@Override
- public void addLabels(Labels labels) {}
+ public void addAttributes(Attributes attributes) {}
@Override
public void addAnnotation(String description) {}
@Override
- public void addAnnotation(String description, Labels labels) {}
+ public void addAnnotation(String description, Attributes attributes) {}
@Override
public void addNetworkEvent(NetworkEvent networkEvent) {}