add some implements of OT.

This commit is contained in:
wusheng 2016-12-20 17:59:46 +08:00
parent 6ee99292a2
commit e5c562c4bb
3 changed files with 53 additions and 6 deletions

View File

@ -10,9 +10,18 @@ import java.util.Map;
* Created by wusheng on 2016/12/20.
*/
public class SkyWalkingSpan implements Span, SpanContext {
private String operationName;
private long startTime;
private Map<String, String> tags;
private final Map<String, String> baggageItems;
SkyWalkingSpan(){
SkyWalkingSpan(String operationName, long startTime, Map<String, String> tags){
this.operationName = operationName;
this.startTime = startTime;
this.tags = tags;
baggageItems = new HashMap<String, String>();
}

View File

@ -5,6 +5,8 @@ import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
@ -17,18 +19,38 @@ import java.util.Map;
public class SkyWalkingSpanBuilder implements Tracer.SpanBuilder {
private String operationName;
private long startTime = 0L;
private final Map<String, String> tags;
private SpanContext parentContext;
SkyWalkingSpanBuilder(String operationName){
this.operationName = operationName;
this.tags = new HashMap<String, String>();
}
/**
* In SkyWalkingTracer, SpanContext will not be used. Tracer will build reference by itself.
*
* @param spanContext
* @return
*/
@Override
public Tracer.SpanBuilder asChildOf(SpanContext spanContext) {
return null;
this.parentContext = spanContext;
return this;
}
/**
* In SkyWalkingTracer, Parent Span will not be used. Tracer will build reference by itself.
* @param span
* @return
*/
@Override
public Tracer.SpanBuilder asChildOf(Span span) {
return null;
asChildOf(span.context());
return this;
}
@Override
@ -42,31 +64,43 @@ public class SkyWalkingSpanBuilder implements Tracer.SpanBuilder {
@Override
public Tracer.SpanBuilder withTag(String key, String value) {
if (key != null && value != null) {
tags.put(key, value);
}
return this;
}
@Override
public Tracer.SpanBuilder withTag(String key, boolean value) {
if (key != null) {
tags.put(key, Boolean.toString(value));
}
return this;
}
@Override
public Tracer.SpanBuilder withTag(String key, Number value) {
if (key != null && value != null) {
tags.put(key, value.toString());
}
return this;
}
@Override
public Tracer.SpanBuilder withStartTimestamp(long microseconds) {
public Tracer.SpanBuilder withStartTimestamp(long startTime) {
this.startTime = startTime;
return this;
}
@Override
public Span start() {
return new SkyWalkingSpan();
return new SkyWalkingSpan(this.operationName, this.startTime, this.tags);
}
@Override
public Iterable<Map.Entry<String, String>> baggageItems() {
return null;
return parentContext == null
? Collections.<String, String>emptyMap().entrySet()
: parentContext.baggageItems();
}
}

View File

@ -5,6 +5,10 @@ import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
/**
* All source code in SkyWalkingTracer acts like an NoopTracer.
* Actually, it is NOT.
* The whole logic will be added after toolkit-activation.
*
* Created by wusheng on 2016/12/20.
*/
public class SkyWalkingTracer implements Tracer{