Skip to content
Closed
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
21 changes: 21 additions & 0 deletions api/src/main/java/io/opentelemetry/common/BooleanValuedKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020, OpenTelemetry Authors
*
* 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 io.opentelemetry.common;

public interface BooleanValuedKey {
String key();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of having this as an interface? Also have you thought about doing something like in the proto, extend the AttributeValue to be AttributeKeyValue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This was another possible suggestion in #1076 . There, we were calling it simply "Attribute". That's another possibility, but would introduce an extra allocation for each attribute application, which probably isn't desirable.

}
21 changes: 21 additions & 0 deletions api/src/main/java/io/opentelemetry/common/DoubleValuedKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020, OpenTelemetry Authors
*
* 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 io.opentelemetry.common;

public interface DoubleValuedKey {
String key();
}
21 changes: 21 additions & 0 deletions api/src/main/java/io/opentelemetry/common/LongValuedKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020, OpenTelemetry Authors
*
* 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 io.opentelemetry.common;

public interface LongValuedKey {
String key();
}
21 changes: 21 additions & 0 deletions api/src/main/java/io/opentelemetry/common/StringValuedKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020, OpenTelemetry Authors
*
* 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 io.opentelemetry.common;

public interface StringValuedKey {
String key();
}
16 changes: 10 additions & 6 deletions api/src/main/java/io/opentelemetry/trace/DefaultSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package io.opentelemetry.trace;

import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.BooleanValuedKey;
import io.opentelemetry.common.DoubleValuedKey;
import io.opentelemetry.common.LongValuedKey;
import io.opentelemetry.common.StringValuedKey;
import io.opentelemetry.internal.Utils;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -73,29 +77,29 @@ static DefaultSpan createRandom() {
}

@Override
public void setAttribute(String key, String value) {
public void setAttribute(String key, AttributeValue value) {
Utils.checkNotNull(key, "key");
Utils.checkNotNull(value, "value");
}

@Override
public void setAttribute(String key, long value) {
public void setAttribute(StringValuedKey key, String value) {
Utils.checkNotNull(key, "key");
}

@Override
public void setAttribute(String key, double value) {
public void setAttribute(DoubleValuedKey key, double value) {
Utils.checkNotNull(key, "key");
}

@Override
public void setAttribute(String key, boolean value) {
public void setAttribute(BooleanValuedKey key, boolean value) {
Utils.checkNotNull(key, "key");
}

@Override
public void setAttribute(String key, AttributeValue value) {
public void setAttribute(LongValuedKey key, long value) {
Utils.checkNotNull(key, "key");
Utils.checkNotNull(value, "value");
}

@Override
Expand Down
16 changes: 10 additions & 6 deletions api/src/main/java/io/opentelemetry/trace/DefaultTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package io.opentelemetry.trace;

import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.BooleanValuedKey;
import io.opentelemetry.common.DoubleValuedKey;
import io.opentelemetry.common.LongValuedKey;
import io.opentelemetry.common.StringValuedKey;
import io.opentelemetry.context.Scope;
import io.opentelemetry.internal.Utils;
import java.util.Map;
Expand Down Expand Up @@ -116,33 +120,33 @@ public NoopSpanBuilder addLink(Link link) {
}

@Override
public NoopSpanBuilder setAttribute(String key, String value) {
public NoopSpanBuilder setAttribute(String key, AttributeValue value) {
Utils.checkNotNull(key, "key");
Utils.checkNotNull(value, "value");
return this;
}

@Override
public NoopSpanBuilder setAttribute(String key, long value) {
public NoopSpanBuilder setAttribute(StringValuedKey key, String value) {
Utils.checkNotNull(key, "key");
return this;
}

@Override
public NoopSpanBuilder setAttribute(String key, double value) {
public NoopSpanBuilder setAttribute(DoubleValuedKey key, double value) {
Utils.checkNotNull(key, "key");
return this;
}

@Override
public NoopSpanBuilder setAttribute(String key, boolean value) {
public NoopSpanBuilder setAttribute(BooleanValuedKey key, boolean value) {
Utils.checkNotNull(key, "key");
return this;
}

@Override
public NoopSpanBuilder setAttribute(String key, AttributeValue value) {
public NoopSpanBuilder setAttribute(LongValuedKey key, long value) {
Utils.checkNotNull(key, "key");
Utils.checkNotNull(value, "value");
return this;
}

Expand Down
40 changes: 22 additions & 18 deletions api/src/main/java/io/opentelemetry/trace/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package io.opentelemetry.trace;

import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.BooleanValuedKey;
import io.opentelemetry.common.DoubleValuedKey;
import io.opentelemetry.common.LongValuedKey;
import io.opentelemetry.common.StringValuedKey;
import java.util.Map;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -84,24 +88,24 @@ enum Kind {
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the attribute will be silently
* dropped. Note: this behavior could change in the future.
*
* @param key the key for this attribute.
* @param value the value for this attribute.
* @since 0.1.0
*/
void setAttribute(String key, @Nullable String value);
void setAttribute(String key, AttributeValue value);

/**
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the attribute will be silently
* dropped. Note: this behavior could change in the future.
*
* @param key the key for this attribute.
* @param value the value for this attribute.
* @since 0.1.0
*/
void setAttribute(String key, long value);
void setAttribute(StringValuedKey key, @Nullable String value);

/**
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
Expand All @@ -111,7 +115,7 @@ enum Kind {
* @param value the value for this attribute.
* @since 0.1.0
*/
void setAttribute(String key, double value);
void setAttribute(DoubleValuedKey key, double value);

/**
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
Expand All @@ -121,7 +125,7 @@ enum Kind {
* @param value the value for this attribute.
* @since 0.1.0
*/
void setAttribute(String key, boolean value);
void setAttribute(BooleanValuedKey key, boolean value);

/**
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
Expand All @@ -131,7 +135,7 @@ enum Kind {
* @param value the value for this attribute.
* @since 0.1.0
*/
void setAttribute(String key, AttributeValue value);
void setAttribute(LongValuedKey key, long value);

/**
* Adds an event to the {@code Span}.
Expand Down Expand Up @@ -263,7 +267,7 @@ enum Kind {

/**
* Returns {@code true} if this {@code Span} records tracing events (e.g. {@link
* #addEvent(String)}, {@link #setAttribute(String, long)}).
* #addEvent(String)}, {@link #setAttribute(LongValuedKey, long)}).
*
* @return {@code true} if this {@code Span} records tracing events.
* @since 0.1.0
Expand Down Expand Up @@ -459,28 +463,29 @@ interface Builder {
* Sets an attribute to the newly created {@code Span}. If {@code Span.Builder} previously
* contained a mapping for the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the attribute will be silently
* dropped. Note: this behavior could change in the future.
*
* @param key the key for this attribute.
* @param value the value for this attribute.
* @return this.
* @throws NullPointerException if {@code key} is {@code null}.
* @throws NullPointerException if {@code value} is {@code null}.
* @since 0.3.0
*/
Builder setAttribute(String key, @Nullable String value);
Builder setAttribute(String key, AttributeValue value);

/**
* Sets an attribute to the newly created {@code Span}. If {@code Span.Builder} previously
* contained a mapping for the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the attribute will be silently
* dropped. Note: this behavior could change in the future.
*
* @param key the key for this attribute.
* @param value the value for this attribute.
* @return this.
* @throws NullPointerException if {@code key} is {@code null}.
* @since 0.3.0
*/
Builder setAttribute(String key, long value);
Builder setAttribute(StringValuedKey key, @Nullable String value);

/**
* Sets an attribute to the newly created {@code Span}. If {@code Span.Builder} previously
Expand All @@ -492,7 +497,7 @@ interface Builder {
* @throws NullPointerException if {@code key} is {@code null}.
* @since 0.3.0
*/
Builder setAttribute(String key, double value);
Builder setAttribute(DoubleValuedKey key, double value);

/**
* Sets an attribute to the newly created {@code Span}. If {@code Span.Builder} previously
Expand All @@ -504,7 +509,7 @@ interface Builder {
* @throws NullPointerException if {@code key} is {@code null}.
* @since 0.3.0
*/
Builder setAttribute(String key, boolean value);
Builder setAttribute(BooleanValuedKey key, boolean value);

/**
* Sets an attribute to the newly created {@code Span}. If {@code Span.Builder} previously
Expand All @@ -514,10 +519,9 @@ interface Builder {
* @param value the value for this attribute.
* @return this.
* @throws NullPointerException if {@code key} is {@code null}.
* @throws NullPointerException if {@code value} is {@code null}.
* @since 0.3.0
*/
Builder setAttribute(String key, AttributeValue value);
Builder setAttribute(LongValuedKey key, long value);

/**
* Sets the {@link Span.Kind} for the newly created {@code Span}. If not called, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@

package io.opentelemetry.trace.attributes;

import io.opentelemetry.common.BooleanValuedKey;
import io.opentelemetry.trace.Span;
import javax.annotation.concurrent.Immutable;

/** Defines the behavior for a span attribute with boolean values. */
@Immutable
public final class BooleanAttributeSetter {
public final class BooleanAttributeSetter implements BooleanValuedKey {

/**
* Returns a new attribute setter.
*
* @param attributeKey the attribute name
* @return the setter object
*/
public static BooleanAttributeSetter create(String attributeKey) {
public static BooleanAttributeSetter booleanKey(String attributeKey) {
return new BooleanAttributeSetter(attributeKey);
}

Expand All @@ -47,6 +48,7 @@ private BooleanAttributeSetter(String attributeKey) {
*
* @return the attribute map key
*/
@Override
public String key() {
return attributeKey;
}
Expand All @@ -58,6 +60,6 @@ public String key() {
* @param value the value for this attribute
*/
public void set(Span span, boolean value) {
span.setAttribute(key(), value);
span.setAttribute(booleanKey(attributeKey), value);
}
}
Loading