implementing a first version of span
MODIFY
src/main/java/com/datadoghq/trace/impl/Span.java
src/main/java/com/datadoghq/trace/impl/Span.java
@@ -3,8 +3,28 @@ package com.datadoghq.trace.impl;
import io.opentracing.SpanContext;
import java.util.Map;
+import java.util.Optional;
+
public class Span implements io.opentracing.Span {
+
+
+ private final String operationName;
+ private Map<String, Object> tags;
+ private long startTime;
+ private final SpanContext parent;
+
+ Span(
+ String operationName,
+ Map<String, Object> tags,
+ Optional<Long> timestamp, SpanContext parent) {
+
+ this.operationName = operationName;
+ this.tags = tags;
+ this.startTime = timestamp.orElse(System.nanoTime());
+ this.parent = parent;
+ }
+
public SpanContext context() {
return null;
}
@@ -68,4 +88,20 @@ public class Span implements io.opentracing.Span {
public io.opentracing.Span log(long l, String s, Object o) {
return null;
}
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public Map<String, Object> getTags() {
+ return this.tags;
+ }
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public SpanContext getParent() {
+ return parent;
+ }
}

MODIFY
src/main/java/com/datadoghq/trace/impl/SpanContext.java
src/main/java/com/datadoghq/trace/impl/SpanContext.java
@@ -4,6 +4,23 @@ package com.datadoghq.trace.impl;
import java.util.Map;
public class SpanContext implements io.opentracing.SpanContext {
+
+ // Public span attributes
+ private String serviceName;
+ private String resourceName;
+ private long spanId;
+ private long traceId;
+ private long parentId;
+ private Map<String, String> baggageItems; // know as 'meta' in dd-trace-py
+ private boolean errorFlag;
+ private Map<String, Object> metrics;
+ private String spanType;
+ private long start;
+ private long duration;
+ // Sampler attributes
+ private boolean sampled;
+
+
public Iterable<Map.Entry<String, String>> baggageItems() {
return null;
}

MODIFY
src/main/java/com/datadoghq/trace/impl/Tracer.java
src/main/java/com/datadoghq/trace/impl/Tracer.java
@@ -4,12 +4,15 @@ import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
public class Tracer implements io.opentracing.Tracer {
- public SpanBuilder buildSpan(String s) {
- return null;
+
+ public SpanBuilder buildSpan(String operationName) {
+ return new SpanBuilder(operationName);
}
public <C> void inject(SpanContext spanContext, Format<C> format, C c) {
@@ -22,6 +25,15 @@ public class Tracer implements io.opentracing.Tracer {
class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {
+ private final String operationName;
+ private Map<String, Object> tags = new HashMap();
+ private Long timestamp;
+ private Optional<SpanContext> parent;
+
+ public SpanBuilder(String operationName) {
+ this.operationName = operationName;
+ }
+
public io.opentracing.Tracer.SpanBuilder asChildOf(SpanContext spanContext) {
return null;
}
@@ -34,23 +46,58 @@ public class Tracer implements io.opentracing.Tracer {
return null;
}
- public io.opentracing.Tracer.SpanBuilder withTag(String s, String s1) {
- return null;
+
+ public io.opentracing.Tracer.SpanBuilder withTag(String tag, Number number) {
+ return withTag(tag, (Object) number);
}
- public io.opentracing.Tracer.SpanBuilder withTag(String s, boolean b) {
- return null;
+ public io.opentracing.Tracer.SpanBuilder withTag(String tag, String string) {
+ return withTag(tag, (Object) string);
}
- public io.opentracing.Tracer.SpanBuilder withTag(String s, Number number) {
- return null;
+ public io.opentracing.Tracer.SpanBuilder withTag(String tag, boolean bool) {
+ return withTag(tag, (Object) bool);
}
- public io.opentracing.Tracer.SpanBuilder withStartTimestamp(long l) {
- return null;
+ private io.opentracing.Tracer.SpanBuilder withTag(String tag, Object value) {
+ this.tags.put(tag, value);
+ return this;
+ }
+
+
+ public io.opentracing.Tracer.SpanBuilder withStartTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ return this;
}
public Span start() {
+
+ // build the context
+ SpanContext context = buildNewSpanContext();
+
+ return new com.datadoghq.trace.impl.Span(
+ this.operationName,
+ this.tags,
+ Optional.ofNullable(this.timestamp),
+ context);
+ }
+
+ private SpanContext buildNewSpanContext() {
+
+ Optional<Object> parentContext = Optional.ofNullable(this.parent);
+ SpanContext context = new com.datadoghq.trace.impl.SpanContext(
+
+ );
+
+
+
+ if (this.parent == null) {
+ long traceId = 123L;
+
+ } else {
+
+ }
+
return null;
}

implementing a first version of span