Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames SpanRecord back to MutableSpan #744

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions brave/src/main/java/brave/RealScopedSpan.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package brave;

import brave.Tracing.SpanReporter;
import brave.internal.recorder.PendingSpanRecords;
import brave.internal.recorder.SpanRecord;
import brave.internal.recorder.MutableSpan;
import brave.internal.recorder.PendingSpans;
import brave.propagation.CurrentTraceContext.Scope;
import brave.propagation.TraceContext;

Expand All @@ -11,25 +11,25 @@ final class RealScopedSpan extends ScopedSpan {

final TraceContext context;
final Scope scope;
final SpanRecord record;
final MutableSpan state;
final Clock clock;
final PendingSpanRecords pendingSpanRecords;
final PendingSpans pendingSpans;
final SpanReporter spanReporter;
final ErrorParser errorParser;

RealScopedSpan(
TraceContext context,
Scope scope,
SpanRecord record,
MutableSpan state,
Clock clock,
PendingSpanRecords pendingSpanRecords,
PendingSpans pendingSpans,
SpanReporter spanReporter,
ErrorParser errorParser
) {
this.context = context;
this.scope = scope;
this.pendingSpanRecords = pendingSpanRecords;
this.record = record;
this.pendingSpans = pendingSpans;
this.state = state;
this.clock = clock;
this.spanReporter = spanReporter;
this.errorParser = errorParser;
Expand All @@ -44,12 +44,12 @@ final class RealScopedSpan extends ScopedSpan {
}

@Override public ScopedSpan annotate(String value) {
record.annotate(clock.currentTimeMicroseconds(), value);
state.annotate(clock.currentTimeMicroseconds(), value);
return this;
}

@Override public ScopedSpan tag(String key, String value) {
record.tag(key, value);
state.tag(key, value);
return this;
}

Expand All @@ -60,9 +60,9 @@ final class RealScopedSpan extends ScopedSpan {

@Override public void finish() {
scope.close();
if (!pendingSpanRecords.remove(context)) return; // don't double-report
spanReporter.report(context, record);
record.finishTimestamp(clock.currentTimeMicroseconds());
if (!pendingSpans.remove(context)) return; // don't double-report
spanReporter.report(context, state);
state.finishTimestamp(clock.currentTimeMicroseconds());
}

@Override public boolean equals(Object o) {
Expand Down
76 changes: 38 additions & 38 deletions brave/src/main/java/brave/RealSpan.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package brave;

import brave.Tracing.SpanReporter;
import brave.internal.recorder.PendingSpanRecords;
import brave.internal.recorder.SpanRecord;
import brave.internal.recorder.MutableSpan;
import brave.internal.recorder.PendingSpans;
import brave.propagation.TraceContext;
import zipkin2.Endpoint;

/** This wraps the public api and guards access to a mutable span. */
final class RealSpan extends Span {

final TraceContext context;
final PendingSpanRecords pendingSpanRecords;
final SpanRecord record;
final PendingSpans pendingSpans;
final MutableSpan state;
final Clock clock;
final SpanReporter spanReporter;
final ErrorParser errorParser;
final RealSpanCustomizer customizer;

RealSpan(TraceContext context,
PendingSpanRecords pendingSpanRecords,
SpanRecord record,
PendingSpans pendingSpans,
MutableSpan state,
Clock clock,
SpanReporter spanReporter,
ErrorParser errorParser) {
this.context = context;
this.pendingSpanRecords = pendingSpanRecords;
this.record = record;
this.pendingSpans = pendingSpans;
this.state = state;
this.clock = clock;
this.customizer = new RealSpanCustomizer(context, record, clock);
this.customizer = new RealSpanCustomizer(context, state, clock);
this.spanReporter = spanReporter;
this.errorParser = errorParser;
}
Expand All @@ -41,30 +41,30 @@ final class RealSpan extends Span {
}

@Override public SpanCustomizer customizer() {
return new RealSpanCustomizer(context, record, clock);
return new RealSpanCustomizer(context, state, clock);
}

@Override public Span start() {
return start(clock.currentTimeMicroseconds());
}

@Override public Span start(long timestamp) {
synchronized (record) {
record.startTimestamp(timestamp);
synchronized (state) {
state.startTimestamp(timestamp);
}
return this;
}

@Override public Span name(String name) {
synchronized (record) {
record.name(name);
synchronized (state) {
state.name(name);
}
return this;
}

@Override public Span kind(Kind kind) {
synchronized (record) {
record.kind(kind);
synchronized (state) {
state.kind(kind);
}
return this;
}
Expand All @@ -77,36 +77,36 @@ final class RealSpan extends Span {
// Modern instrumentation should not send annotations such as this, but we leniently
// accept them rather than fail. This for example allows old bridges like to Brave v3 to work
if ("cs".equals(value)) {
synchronized (record) {
record.kind(Span.Kind.CLIENT);
record.startTimestamp(timestamp);
synchronized (state) {
state.kind(Span.Kind.CLIENT);
state.startTimestamp(timestamp);
}
} else if ("sr".equals(value)) {
synchronized (record) {
record.kind(Span.Kind.SERVER);
record.startTimestamp(timestamp);
synchronized (state) {
state.kind(Span.Kind.SERVER);
state.startTimestamp(timestamp);
}
} else if ("cr".equals(value)) {
synchronized (record) {
record.kind(Span.Kind.CLIENT);
synchronized (state) {
state.kind(Span.Kind.CLIENT);
}
finish(timestamp);
} else if ("ss".equals(value)) {
synchronized (record) {
record.kind(Span.Kind.SERVER);
synchronized (state) {
state.kind(Span.Kind.SERVER);
}
finish(timestamp);
} else {
synchronized (record) {
record.annotate(timestamp, value);
synchronized (state) {
state.annotate(timestamp, value);
}
}
return this;
}

@Override public Span tag(String key, String value) {
synchronized (record) {
record.tag(key, value);
synchronized (state) {
state.tag(key, value);
}
return this;
}
Expand All @@ -117,8 +117,8 @@ final class RealSpan extends Span {
}

@Override public Span remoteEndpoint(Endpoint remoteEndpoint) {
synchronized (record) {
record.remoteEndpoint(remoteEndpoint);
synchronized (state) {
state.remoteEndpoint(remoteEndpoint);
}
return this;
}
Expand All @@ -128,20 +128,20 @@ final class RealSpan extends Span {
}

@Override public void finish(long timestamp) {
if (!pendingSpanRecords.remove(context)) return;
synchronized (record) {
record.finishTimestamp(timestamp);
if (!pendingSpans.remove(context)) return;
synchronized (state) {
state.finishTimestamp(timestamp);
}
spanReporter.report(context, record);
spanReporter.report(context, state);
}

@Override public void abandon() {
pendingSpanRecords.remove(context);
pendingSpans.remove(context);
}

@Override public void flush() {
abandon();
spanReporter.report(context, record);
spanReporter.report(context, state);
}

@Override public String toString() {
Expand Down
20 changes: 10 additions & 10 deletions brave/src/main/java/brave/RealSpanCustomizer.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package brave;

import brave.internal.recorder.SpanRecord;
import brave.internal.recorder.MutableSpan;
import brave.propagation.TraceContext;

/** This wraps the public api and guards access to a mutable span. */
final class RealSpanCustomizer implements SpanCustomizer {

final TraceContext context;
final SpanRecord record;
final MutableSpan state;
final Clock clock;

RealSpanCustomizer(TraceContext context, SpanRecord record, Clock clock) {
RealSpanCustomizer(TraceContext context, MutableSpan state, Clock clock) {
this.context = context;
this.record = record;
this.state = state;
this.clock = clock;
}

@Override public SpanCustomizer name(String name) {
synchronized (record) {
record.name(name);
synchronized (state) {
state.name(name);
}
return this;
}

@Override public SpanCustomizer annotate(String value) {
long timestamp = clock.currentTimeMicroseconds();
synchronized (record) {
record.annotate(timestamp, value);
synchronized (state) {
state.annotate(timestamp, value);
}
return this;
}

@Override public SpanCustomizer tag(String key, String value) {
synchronized (record) {
record.tag(key, value);
synchronized (state) {
state.tag(key, value);
}
return this;
}
Expand Down
40 changes: 20 additions & 20 deletions brave/src/main/java/brave/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import brave.internal.Nullable;
import brave.internal.Platform;
import brave.internal.recorder.PendingSpanRecord;
import brave.internal.recorder.PendingSpanRecords;
import brave.internal.recorder.SpanRecord;
import brave.internal.recorder.MutableSpan;
import brave.internal.recorder.PendingSpan;
import brave.internal.recorder.PendingSpans;
import brave.propagation.CurrentTraceContext;
import brave.propagation.Propagation;
import brave.propagation.SamplingFlags;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class Tracer {
final Clock clock;
final Propagation.Factory propagationFactory;
final Tracing.SpanReporter spanReporter; // for toString
final PendingSpanRecords pendingSpanRecords;
final PendingSpans pendingSpans;
final Sampler sampler;
final ErrorParser errorParser;
final CurrentTraceContext currentTraceContext;
Expand All @@ -75,7 +75,7 @@ public class Tracer {
Clock clock,
Propagation.Factory propagationFactory,
Tracing.SpanReporter spanReporter,
PendingSpanRecords pendingSpanRecords,
PendingSpans pendingSpans,
Sampler sampler,
ErrorParser errorParser,
CurrentTraceContext currentTraceContext,
Expand All @@ -86,7 +86,7 @@ public class Tracer {
this.clock = clock;
this.propagationFactory = propagationFactory;
this.spanReporter = spanReporter;
this.pendingSpanRecords = pendingSpanRecords;
this.pendingSpans = pendingSpans;
this.sampler = sampler;
this.errorParser = errorParser;
this.currentTraceContext = currentTraceContext;
Expand All @@ -113,7 +113,7 @@ public Tracer withSampler(Sampler sampler) {
clock,
propagationFactory,
spanReporter,
pendingSpanRecords,
pendingSpans,
sampler,
errorParser,
currentTraceContext,
Expand Down Expand Up @@ -250,11 +250,11 @@ public Span toSpan(TraceContext context) {
TraceContext decorated = propagationFactory.decorate(context);
if (isNoop(decorated)) return new NoopSpan(decorated);
// allocate a mutable span in case multiple threads call this method.. they'll use the same data
PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(decorated);
PendingSpan pendingSpan = pendingSpans.getOrCreate(decorated);
return new RealSpan(decorated,
pendingSpanRecords,
pendingSpanRecord.span(),
pendingSpanRecord.clock(),
pendingSpans,
pendingSpan.state(),
pendingSpan.clock(),
spanReporter,
errorParser
);
Expand Down Expand Up @@ -319,8 +319,8 @@ public SpanCustomizer currentSpanCustomizer() {
// note: we don't need to decorate the context for propagation as it is only used for toString
TraceContext context = currentTraceContext.get();
if (context == null || isNoop(context)) return NoopSpanCustomizer.INSTANCE;
PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(context);
return new RealSpanCustomizer(context, pendingSpanRecord.span(), pendingSpanRecord.clock());
PendingSpan pendingSpan = pendingSpans.getOrCreate(context);
return new RealSpanCustomizer(context, pendingSpan.state(), pendingSpan.clock());
}

/**
Expand Down Expand Up @@ -378,12 +378,12 @@ public ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext
TraceContext context = propagationFactory.decorate(newContextBuilder(parent, sampler).build());
CurrentTraceContext.Scope scope = currentTraceContext.newScope(context);
if (isNoop(context)) return new NoopScopedSpan(context, scope);
PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(context);
Clock clock = pendingSpanRecord.clock();
SpanRecord record = pendingSpanRecord.span();
record.name(name);
record.startTimestamp(clock.currentTimeMicroseconds());
return new RealScopedSpan(context, scope, record, clock, pendingSpanRecords, spanReporter,
PendingSpan pendingSpan = pendingSpans.getOrCreate(context);
Clock clock = pendingSpan.clock();
MutableSpan state = pendingSpan.state();
state.name(name);
state.startTimestamp(clock.currentTimeMicroseconds());
return new RealScopedSpan(context, scope, state, clock, pendingSpans, spanReporter,
errorParser);
}

Expand All @@ -409,7 +409,7 @@ public static final class SpanInScope implements Closeable {

@Override public String toString() {
TraceContext currentSpan = currentTraceContext.get();
List<zipkin2.Span> inFlight = pendingSpanRecords.snapshot();
List<zipkin2.Span> inFlight = pendingSpans.snapshot();
return "Tracer{"
+ (currentSpan != null ? ("currentSpan=" + currentSpan + ", ") : "")
+ (inFlight.size() > 0 ? ("inFlight=" + inFlight + ", ") : "")
Expand Down
Loading