diff options
Diffstat (limited to 'impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java')
-rw-r--r-- | impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java b/impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java index 7715a89f..0a22f726 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java +++ b/impl_core/src/main/java/io/opencensus/implcore/trace/SpanImpl.java @@ -241,16 +241,36 @@ public final class SpanImpl extends Span implements Element<SpanImpl> { } @Override + public void putAttribute(String key, AttributeValue value) { + if (!getOptions().contains(Options.RECORD_EVENTS)) { + return; + } + synchronized (this) { + if (hasBeenEnded) { + logger.log(Level.FINE, "Calling putAttributes() on an ended Span."); + return; + } + getInitializedAttributes().putAttribute(key, value); + } + } + + @Override + @SuppressWarnings("deprecation") public void addAttributes(Map<String, AttributeValue> attributes) { + putAttributes(attributes); + } + + @Override + public void putAttributes(Map<String, AttributeValue> attributes) { if (!getOptions().contains(Options.RECORD_EVENTS)) { return; } synchronized (this) { if (hasBeenEnded) { - logger.log(Level.FINE, "Calling addAttributes() on an ended Span."); + logger.log(Level.FINE, "Calling putAttributes() on an ended Span."); return; } - getInitializedAttributes().addAttributes(attributes); + getInitializedAttributes().putAttributes(attributes); } } @@ -437,9 +457,16 @@ public final class SpanImpl extends Span implements Element<SpanImpl> { this.capacity = capacity; } - // Users must call this method instead of put or putAll to keep count of the total number of - // entries inserted. - private void addAttributes(Map<String, AttributeValue> attributes) { + // Users must call this method instead of put to keep count of the total number of entries + // inserted. + private void putAttribute(String key, AttributeValue value) { + totalRecordedAttributes += 1; + put(key, value); + } + + // Users must call this method instead of putAll to keep count of the total number of entries + // inserted. + private void putAttributes(Map<String, AttributeValue> attributes) { totalRecordedAttributes += attributes.size(); putAll(attributes); } |