Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from objectiser/spanfields
Browse files Browse the repository at this point in the history
Make the fields in the abstract span available to concrete impls
  • Loading branch information
michaelsembwever authored Sep 11, 2016
2 parents 0b95031 + 588f613 commit d3c218d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
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;
import java.util.concurrent.TimeUnit;

abstract class AbstractSpan implements Span, SpanContext {

String operationName;
private String operationName;

protected final Map<String,String> baggage = new HashMap<>();
private final Map<String,String> baggage = new HashMap<>();

private final Instant start;
private Duration duration;
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -82,6 +102,10 @@ public final Span setTag(String key, Number value) {
return this;
}

public final Map<String,Object> getTags() {
return Collections.unmodifiableMap(tags);
}

@Override
public AbstractSpan setBaggageItem(String key, String value) {
baggage.put(key, value);
Expand All @@ -98,6 +122,10 @@ public final Iterable<Map.Entry<String,String>> baggageItems() {
return baggage.entrySet();
}

public final Map<String,String> getBaggage() {
return Collections.unmodifiableMap(baggage);
}

@Override
public final Span log(String message, /* @Nullable */ Object payload) {
Instant now = Instant.now();
Expand All @@ -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<LogData> getLogs() {
return Collections.unmodifiableList(logs);
}

final class LogData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ AbstractSpanBuilder withStateItem(String key, Object value) {

@Override
Map<String, Object> getTraceState(SpanContext spanContext) {
return new HashMap<>(((AbstractSpan)spanContext).baggage);
return new HashMap<>(((AbstractSpan)spanContext).getBaggage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
final class TestTextMapInjectorImpl implements Injector<TextMap> {
@Override
public void inject(SpanContext spanContext, TextMap carrier) {
carrier.put("test-marker", ((AbstractSpan)spanContext).operationName);
carrier.put("test-marker", ((AbstractSpan)spanContext).getOperationName());
}
}

0 comments on commit d3c218d

Please sign in to comment.