diff options
Diffstat (limited to 'api/src/main/java/io/opencensus/trace/Span.java')
-rw-r--r-- | api/src/main/java/io/opencensus/trace/Span.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/api/src/main/java/io/opencensus/trace/Span.java b/api/src/main/java/io/opencensus/trace/Span.java index c609c13f..20a859e1 100644 --- a/api/src/main/java/io/opencensus/trace/Span.java +++ b/api/src/main/java/io/opencensus/trace/Span.java @@ -77,10 +77,38 @@ public abstract class Span { } /** - * Adds a set of attributes to the {@code Span}. + * 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. * + * @param key the key for this attribute. + * @param value the value for this attribute. + */ + public void putAttribute(String key, AttributeValue value) { + // Not final because for performance reasons we want to override this in the implementation. + // Also a default implementation is needed to not break the compatibility (users may extend this + // for testing). + addAttributes(Collections.singletonMap(key, value)); + } + + /** + * Sets a set of attributes to the {@code Span}. The effect of this call is equivalent to that of + * calling {@link #putAttribute(String, AttributeValue)} once for each element in the specified + * map. + * + * @param attributes the attributes that will be added and associated with the {@code Span}. + */ + public void putAttributes(Map<String, AttributeValue> attributes) { + // Not final because we want to start overriding this method from the beginning, this will + // allow us to remove the addAttributes faster. + addAttributes(attributes); + } + + + /** + * @deprecated Use {@link #putAttributes(Map)} * @param attributes the attributes that will be added and associated with the {@code Span}. */ + @Deprecated public abstract void addAttributes(Map<String, AttributeValue> attributes); /** @@ -97,7 +125,7 @@ public abstract class Span { * * @param description the description of the annotation time event. * @param attributes the attributes that will be added; these are associated with this annotation, - * not the {@code Span} as for {@link #addAttributes}. + * not the {@code Span} as for {@link #addAttributes(Map)}. */ public abstract void addAnnotation(String description, Map<String, AttributeValue> attributes); |