diff options
author | Bogdan Drutu <bdrutu@google.com> | 2018-08-09 10:09:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-09 10:09:28 -0700 |
commit | 52f38e48e2ac6cb65e28dcd97b4f7e9650357bba (patch) | |
tree | b5dc40e7e3805ece5011f1d253622e69bccc15f6 /api/src/main | |
parent | 18aa2793facbb3d7e252ac32e6bb4d09f08a37ac (diff) | |
download | opencensus-java-52f38e48e2ac6cb65e28dcd97b4f7e9650357bba.tar.gz |
Add Tracestate into SpanContext. (#1359)
* Add Tracestate into SpanContext.
* Remove empty constructor from Tracestate.Builder
* Add info in the changelog.
Diffstat (limited to 'api/src/main')
-rw-r--r-- | api/src/main/java/io/opencensus/trace/SpanContext.java | 42 | ||||
-rw-r--r-- | api/src/main/java/io/opencensus/trace/Tracestate.java | 6 |
2 files changed, 37 insertions, 11 deletions
diff --git a/api/src/main/java/io/opencensus/trace/SpanContext.java b/api/src/main/java/io/opencensus/trace/SpanContext.java index 66a6bfbc..49ed751b 100644 --- a/api/src/main/java/io/opencensus/trace/SpanContext.java +++ b/api/src/main/java/io/opencensus/trace/SpanContext.java @@ -30,9 +30,11 @@ import javax.annotation.concurrent.Immutable; */ @Immutable public final class SpanContext { + private static final Tracestate TRACESTATE_DEFAULT = Tracestate.builder().build(); private final TraceId traceId; private final SpanId spanId; private final TraceOptions traceOptions; + private final Tracestate tracestate; /** * The invalid {@code SpanContext}. @@ -40,7 +42,7 @@ public final class SpanContext { * @since 0.5 */ public static final SpanContext INVALID = - new SpanContext(TraceId.INVALID, SpanId.INVALID, TraceOptions.DEFAULT); + new SpanContext(TraceId.INVALID, SpanId.INVALID, TraceOptions.DEFAULT, TRACESTATE_DEFAULT); /** * Creates a new {@code SpanContext} with the given identifiers and options. @@ -49,10 +51,26 @@ public final class SpanContext { * @param spanId the span identifier of the span context. * @param traceOptions the trace options for the span context. * @return a new {@code SpanContext} with the given identifiers and options. - * @since 0.5 + * @deprecated use {@link #create(TraceId, SpanId, TraceOptions, Tracestate)}. */ + @Deprecated public static SpanContext create(TraceId traceId, SpanId spanId, TraceOptions traceOptions) { - return new SpanContext(traceId, spanId, traceOptions); + return create(traceId, spanId, traceOptions, TRACESTATE_DEFAULT); + } + + /** + * Creates a new {@code SpanContext} with the given identifiers and options. + * + * @param traceId the trace identifier of the span context. + * @param spanId the span identifier of the span context. + * @param traceOptions the trace options for the span context. + * @param tracestate the trace state for the span context. + * @return a new {@code SpanContext} with the given identifiers and options. + * @since 0.16 + */ + public static SpanContext create( + TraceId traceId, SpanId spanId, TraceOptions traceOptions, Tracestate tracestate) { + return new SpanContext(traceId, spanId, traceOptions, tracestate); } /** @@ -76,9 +94,9 @@ public final class SpanContext { } /** - * Returns the trace options associated with this {@code SpanContext}. + * Returns the {@code TraceOptions} associated with this {@code SpanContext}. * - * @return the trace options associated with this {@code SpanContext}. + * @return the {@code TraceOptions} associated with this {@code SpanContext}. * @since 0.5 */ public TraceOptions getTraceOptions() { @@ -86,6 +104,16 @@ public final class SpanContext { } /** + * Returns the {@code Tracestate} associated with this {@code SpanContext}. + * + * @return the {@code Tracestate} associated with this {@code SpanContext}. + * @since 0.5 + */ + public Tracestate getTracestate() { + return tracestate; + } + + /** * Returns true if this {@code SpanContext} is valid. * * @return true if this {@code SpanContext} is valid. @@ -127,9 +155,11 @@ public final class SpanContext { + "}"; } - private SpanContext(TraceId traceId, SpanId spanId, TraceOptions traceOptions) { + private SpanContext( + TraceId traceId, SpanId spanId, TraceOptions traceOptions, Tracestate tracestate) { this.traceId = traceId; this.spanId = spanId; this.traceOptions = traceOptions; + this.tracestate = tracestate; } } diff --git a/api/src/main/java/io/opencensus/trace/Tracestate.java b/api/src/main/java/io/opencensus/trace/Tracestate.java index 5535a0ac..f88d3bd3 100644 --- a/api/src/main/java/io/opencensus/trace/Tracestate.java +++ b/api/src/main/java/io/opencensus/trace/Tracestate.java @@ -81,7 +81,7 @@ public abstract class Tracestate { * @since 0.16 */ public static Builder builder() { - return new Builder(); + return new Builder(Builder.EMPTY); } /** @@ -108,10 +108,6 @@ public abstract class Tracestate { // subclass (the auto-value generate class). private static final Tracestate EMPTY = create(Collections.<Entry>emptyList()); - private Builder() { - this(EMPTY); - } - private Builder(Tracestate parent) { Utils.checkNotNull(parent, "parent"); this.parent = parent; |