adding a close method to flush traces

This commit is contained in:
Guillaume Polaert 2017-05-16 12:11:58 +02:00
parent c5184070f4
commit 0c06397094
1 changed files with 31 additions and 27 deletions

View File

@ -66,10 +66,10 @@ public class DDTracer implements io.opentracing.Tracer {
} }
public DDTracer(Writer writer, Sampler sampler) { public DDTracer(Writer writer, Sampler sampler) {
this(UNASSIGNED_DEFAULT_SERVICE_NAME,writer,sampler); this(UNASSIGNED_DEFAULT_SERVICE_NAME, writer, sampler);
} }
public DDTracer(String defaultServiceName,Writer writer, Sampler sampler) { public DDTracer(String defaultServiceName, Writer writer, Sampler sampler) {
this.defaultServiceName = defaultServiceName; this.defaultServiceName = defaultServiceName;
this.writer = writer; this.writer = writer;
this.writer.start(); this.writer.start();
@ -92,7 +92,7 @@ public class DDTracer implements io.opentracing.Tracer {
* *
* @param decorator The decorator in the list * @param decorator The decorator in the list
*/ */
public void addDecorator(DDSpanContextDecorator decorator){ public void addDecorator(DDSpanContextDecorator decorator) {
spanContextDecorators.add(decorator); spanContextDecorators.add(decorator);
} }
@ -139,6 +139,10 @@ public class DDTracer implements io.opentracing.Tracer {
} }
} }
public void close() {
writer.close();
}
/** /**
* Spans are built using this builder * Spans are built using this builder
*/ */
@ -181,13 +185,13 @@ public class DDTracer implements io.opentracing.Tracer {
} }
public DDTracer.DDSpanBuilder withTag(String tag, String string) { public DDTracer.DDSpanBuilder withTag(String tag, String string) {
if(tag.equals(DDTags.SERVICE_NAME)){ if (tag.equals(DDTags.SERVICE_NAME)) {
return withServiceName(string); return withServiceName(string);
}else if(tag.equals(DDTags.RESOURCE_NAME)){ } else if (tag.equals(DDTags.RESOURCE_NAME)) {
return withResourceName(string); return withResourceName(string);
}else if(tag.equals(DDTags.SPAN_TYPE)){ } else if (tag.equals(DDTags.SPAN_TYPE)) {
return withSpanType(string); return withSpanType(string);
}else{ } else {
return withTag(tag, (Object) string); return withTag(tag, (Object) string);
} }
} }
@ -249,7 +253,7 @@ public class DDTracer implements io.opentracing.Tracer {
// Private methods // Private methods
private DDTracer.DDSpanBuilder withTag(String tag, Object value) { private DDTracer.DDSpanBuilder withTag(String tag, Object value) {
if (this.tags.isEmpty()){ if (this.tags.isEmpty()) {
this.tags = new HashMap<String, Object>(); this.tags = new HashMap<String, Object>();
} }
this.tags.put(tag, value); this.tags.put(tag, value);
@ -281,9 +285,9 @@ public class DDTracer implements io.opentracing.Tracer {
String serviceName = this.serviceName; String serviceName = this.serviceName;
if (serviceName == null) { if (serviceName == null) {
if(p != null){ if (p != null && p.getServiceName() != null) {
serviceName = p.getServiceName(); serviceName = p.getServiceName();
}else{ } else {
serviceName = defaultServiceName; serviceName = defaultServiceName;
} }
} }