diff --git a/opentracing-impl-java8/src/main/java/io/opentracing/AbstractSpan.java b/opentracing-impl-java8/src/main/java/io/opentracing/AbstractSpan.java index 1c6fac45..2262d6fd 100644 --- a/opentracing-impl-java8/src/main/java/io/opentracing/AbstractSpan.java +++ b/opentracing-impl-java8/src/main/java/io/opentracing/AbstractSpan.java @@ -16,6 +16,7 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,9 +24,9 @@ abstract class AbstractSpan implements Span, SpanContext { - String operationName; + private String operationName; - protected final Map baggage = new HashMap<>(); + private final Map baggage = new HashMap<>(); private final Instant start; private Duration duration; @@ -51,6 +52,7 @@ public void finish() { assert null == duration; duration = Duration.between(start, Instant.now()); } + @Override public void finish(long finishMicros) { long finishEpochSeconds = TimeUnit.MICROSECONDS.toSeconds(finishMicros); @@ -59,6 +61,24 @@ public void finish(long finishMicros) { duration = Duration.between(start, Instant.ofEpochSecond(finishEpochSeconds, nanos)); } + public final String getOperationName() { + return operationName; + } + + @Override + public Span setOperationName(String operationName) { + this.operationName = operationName; + return this; + } + + public final Instant getStart() { + return start; + } + + public final Duration getDuration() { + return duration; + } + @Override public final void close() { finish(); @@ -82,6 +102,10 @@ public final Span setTag(String key, Number value) { return this; } + public final Map getTags() { + return Collections.unmodifiableMap(tags); + } + @Override public AbstractSpan setBaggageItem(String key, String value) { baggage.put(key, value); @@ -98,6 +122,10 @@ public final Iterable> baggageItems() { return baggage.entrySet(); } + public final Map getBaggage() { + return Collections.unmodifiableMap(baggage); + } + @Override public final Span log(String message, /* @Nullable */ Object payload) { Instant now = Instant.now(); @@ -114,10 +142,8 @@ public final Span log(long instantMicroseconds, String message, /* @Nullable */ return this; } - @Override - public Span setOperationName(String operationName) { - this.operationName = operationName; - return this; + public final List getLogs() { + return Collections.unmodifiableList(logs); } final class LogData { diff --git a/opentracing-impl-java8/src/test/java/io/opentracing/AbstractTracerTest.java b/opentracing-impl-java8/src/test/java/io/opentracing/AbstractTracerTest.java index 0d4ad212..a5c7b186 100644 --- a/opentracing-impl-java8/src/test/java/io/opentracing/AbstractTracerTest.java +++ b/opentracing-impl-java8/src/test/java/io/opentracing/AbstractTracerTest.java @@ -37,7 +37,7 @@ public void testBuildSpan() { Tracer.SpanBuilder result = instance.buildSpan(operationName); AbstractSpan span = (AbstractSpan) result.start(); assertNotNull("Expected to create a valid Span", span); - assertEquals("Expected to create a Span with operationName", operationName, span.operationName); + assertEquals("Expected to create a Span with operationName", operationName, span.getOperationName()); } /** @@ -114,7 +114,7 @@ AbstractSpanBuilder withStateItem(String key, Object value) { @Override Map getTraceState(SpanContext spanContext) { - return new HashMap<>(((AbstractSpan)spanContext).baggage); + return new HashMap<>(((AbstractSpan)spanContext).getBaggage()); } } diff --git a/opentracing-impl-java8/src/test/java/io/opentracing/TestTextMapInjectorImpl.java b/opentracing-impl-java8/src/test/java/io/opentracing/TestTextMapInjectorImpl.java index f738c8d3..4a2f09bc 100644 --- a/opentracing-impl-java8/src/test/java/io/opentracing/TestTextMapInjectorImpl.java +++ b/opentracing-impl-java8/src/test/java/io/opentracing/TestTextMapInjectorImpl.java @@ -19,6 +19,6 @@ final class TestTextMapInjectorImpl implements Injector { @Override public void inject(SpanContext spanContext, TextMap carrier) { - carrier.put("test-marker", ((AbstractSpan)spanContext).operationName); + carrier.put("test-marker", ((AbstractSpan)spanContext).getOperationName()); } }