diff --git a/opentracing-api/src/main/java/io/opentracing/Span.java b/opentracing-api/src/main/java/io/opentracing/Span.java index a8e2f144..cd6b28f0 100644 --- a/opentracing-api/src/main/java/io/opentracing/Span.java +++ b/opentracing-api/src/main/java/io/opentracing/Span.java @@ -13,6 +13,7 @@ */ package io.opentracing; +import io.opentracing.tag.AbstractTag; import java.util.Map; /** @@ -44,6 +45,9 @@ public interface Span { /** Same as {@link #setTag(String, String)}, but for numeric values. */ Span setTag(String key, Number value); + /** Same as {@link #setTag(String, String)}, but with typed value. */ + Span setTag(AbstractTag key, T value); + /** * Log key:value pairs to the Span with the current walltime timestamp. * diff --git a/opentracing-api/src/main/java/io/opentracing/Tracer.java b/opentracing-api/src/main/java/io/opentracing/Tracer.java index fad37cfe..edd263f3 100644 --- a/opentracing-api/src/main/java/io/opentracing/Tracer.java +++ b/opentracing-api/src/main/java/io/opentracing/Tracer.java @@ -14,6 +14,7 @@ package io.opentracing; import io.opentracing.propagation.Format; +import io.opentracing.tag.AbstractTag; /** * Tracer is a simple, thin interface for Span creation and propagation across arbitrary transports. @@ -173,6 +174,9 @@ interface SpanBuilder { /** Same as {@link Span#setTag(String, Number)}, but for the span being built. */ SpanBuilder withTag(String key, Number value); + /** Same as {@link AbstractTag#set(Span, T)}, but for the span being built. */ + SpanBuilder withTag(AbstractTag tag, T value); + /** Specify a timestamp of when the Span was started, represented in microseconds since epoch. */ SpanBuilder withStartTimestamp(long microseconds); diff --git a/opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java b/opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java index 92a87a14..b2594f4d 100644 --- a/opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java +++ b/opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java @@ -14,6 +14,9 @@ package io.opentracing.mock; import io.opentracing.References; +import io.opentracing.Span; +import io.opentracing.SpanContext; +import io.opentracing.tag.AbstractTag; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -22,9 +25,6 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicLong; -import io.opentracing.Span; -import io.opentracing.SpanContext; - /** * MockSpans are created via MockTracer.buildSpan(...), but they are also returned via calls to * MockTracer.finishedSpans(). They provide accessors to all Span state. @@ -136,6 +136,11 @@ public MockSpan setTag(String key, Number value) { return setObjectTag(key, value); } + @Override + public Span setTag(AbstractTag key, T value) { + return setObjectTag(key.getKey(), value); + } + private synchronized MockSpan setObjectTag(String key, Object value) { finishedCheck("Adding tag {%s:%s} to already finished span", key, value); tags.put(key, value); diff --git a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java index 25670a69..36336314 100644 --- a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java +++ b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java @@ -34,6 +34,7 @@ import io.opentracing.propagation.Binary; import io.opentracing.propagation.Format; import io.opentracing.propagation.TextMap; +import io.opentracing.tag.AbstractTag; import io.opentracing.util.ThreadLocalScopeManager; /** @@ -346,6 +347,12 @@ public SpanBuilder withTag(String key, Number value) { return this; } + @Override + public Tracer.SpanBuilder withTag(AbstractTag tag, T value) { + this.initialTags.put(tag.getKey(), value); + return this; + } + @Override public SpanBuilder withStartTimestamp(long microseconds) { this.startMicros = microseconds; diff --git a/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpan.java b/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpan.java index e1aa9899..94f71778 100644 --- a/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpan.java +++ b/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpan.java @@ -15,6 +15,7 @@ import io.opentracing.Span; import io.opentracing.SpanContext; +import io.opentracing.tag.AbstractTag; import java.util.Map; @@ -42,6 +43,11 @@ public void finish(long finishMicros) {} @Override public NoopSpan setTag(String key, Number value) { return this; } + @Override + public Span setTag(AbstractTag key, T value) { + return this; + } + @Override public NoopSpan log(Map fields) { return this; } diff --git a/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpanBuilder.java b/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpanBuilder.java index db7a0c5e..e6ea1c4a 100644 --- a/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpanBuilder.java +++ b/opentracing-noop/src/main/java/io/opentracing/noop/NoopSpanBuilder.java @@ -17,9 +17,7 @@ import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; - -import java.util.Collections; -import java.util.Map; +import io.opentracing.tag.AbstractTag; public interface NoopSpanBuilder extends Tracer.SpanBuilder { NoopSpanBuilder INSTANCE = new NoopSpanBuilderImpl(); @@ -60,6 +58,11 @@ public Tracer.SpanBuilder withTag(String key, Number value) { return this; } + @Override + public Tracer.SpanBuilder withTag(AbstractTag key, T value) { + return this; + } + @Override public Tracer.SpanBuilder withStartTimestamp(long microseconds) { return this;