Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/main/java/com/datadoghq/trace/impl/DDSpan.java
This commit is contained in:
commit
ee9f91219b
|
@ -1,11 +1,15 @@
|
|||
package com.datadoghq.trace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.opentracing.Span;
|
||||
|
||||
public interface SpanSerializer {
|
||||
|
||||
public String serialize(Span t) throws Exception;
|
||||
|
||||
public String serialize(List<Span> t) throws Exception;
|
||||
|
||||
public Span deserialize(String str) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,11 @@ import io.opentracing.SpanContext;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
|
||||
|
||||
public class DDSpan implements io.opentracing.Span {
|
||||
|
||||
|
@ -48,36 +53,36 @@ public class DDSpan implements io.opentracing.Span {
|
|||
return this.setTag(tag, value);
|
||||
}
|
||||
|
||||
public io.opentracing.Span setTag(String tag, boolean value) {
|
||||
public Span setTag(String tag, boolean value) {
|
||||
return this.setTag(tag, value);
|
||||
}
|
||||
|
||||
public io.opentracing.Span setTag(String tag, Number value) {
|
||||
public Span setTag(String tag, Number value) {
|
||||
return this.setTag(tag, (Object) value);
|
||||
}
|
||||
|
||||
private io.opentracing.Span setTag(String tag, Object value) {
|
||||
private Span setTag(String tag, Object value) {
|
||||
this.tags.put(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(Map<String, ?> map) {
|
||||
public Span log(Map<String, ?> map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(long l, Map<String, ?> map) {
|
||||
public Span log(long l, Map<String, ?> map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(String s) {
|
||||
public Span log(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(long l, String s) {
|
||||
public Span log(long l, String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public io.opentracing.Span setBaggageItem(String key, String value) {
|
||||
public Span setBaggageItem(String key, String value) {
|
||||
this.context.setBaggageItem(key, value);
|
||||
return this;
|
||||
}
|
||||
|
@ -86,36 +91,70 @@ public class DDSpan implements io.opentracing.Span {
|
|||
return this.context.getBaggageItem(key);
|
||||
}
|
||||
|
||||
public io.opentracing.Span setOperationName(String operationName) {
|
||||
public Span setOperationName(String operationName) {
|
||||
this.operationName = operationName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(String s, Object o) {
|
||||
public Span log(String s, Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(long l, String s, Object o) {
|
||||
public Span log(long l, String s, Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Getters and JSON serialisation instructions
|
||||
|
||||
@JsonGetter(value="name")
|
||||
public String getOperationName() {
|
||||
return operationName;
|
||||
}
|
||||
|
||||
@JsonGetter(value="meta")
|
||||
public Map<String, Object> getTags() {
|
||||
return this.tags;
|
||||
}
|
||||
|
||||
@JsonGetter(value="start")
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
return startTime * 1000000;
|
||||
}
|
||||
|
||||
public DDSpanContext getContext() {
|
||||
return context;
|
||||
@JsonGetter(value="duration")
|
||||
public long getDurationNano(){
|
||||
return durationNano;
|
||||
}
|
||||
|
||||
public DDSpanContext DDContext() {
|
||||
return this.context;
|
||||
public String getService(){
|
||||
return context.getServiceName();
|
||||
}
|
||||
|
||||
@JsonGetter(value="trace_id")
|
||||
public long getTraceId(){
|
||||
return context.getTraceId();
|
||||
}
|
||||
|
||||
@JsonGetter(value="span_id")
|
||||
public long getSpanId(){
|
||||
return context.getSpanId();
|
||||
}
|
||||
|
||||
@JsonGetter(value="parent_id")
|
||||
public long getParentId(){
|
||||
return context.getParentId();
|
||||
}
|
||||
|
||||
@JsonGetter(value="resource")
|
||||
public String getResourceName(){
|
||||
return context.getResourceName()==null?getOperationName():context.getResourceName();
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return context.getSpanType();
|
||||
}
|
||||
|
||||
public int getError(){
|
||||
return context.getErrorFlag()?1:0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,8 +89,8 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
return resourceName;
|
||||
}
|
||||
|
||||
public boolean isErrorFlag() {
|
||||
return this.errorFlag;
|
||||
public boolean getErrorFlag() {
|
||||
return errorFlag;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMetrics() {
|
||||
|
@ -101,7 +101,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
return spanType;
|
||||
}
|
||||
|
||||
public boolean isSampled() {
|
||||
public boolean getSampled() {
|
||||
return sampled;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
package com.datadoghq.trace.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.datadoghq.trace.SpanSerializer;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import io.opentracing.Span;
|
||||
|
||||
public class DDSpanSerializer implements SpanSerializer {
|
||||
|
||||
protected final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public String serialize(io.opentracing.Span t) throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(t);
|
||||
public String serialize(Span span) throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(span);
|
||||
}
|
||||
|
||||
public String serialize(List<Span> spans) throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(spans);
|
||||
}
|
||||
|
||||
public io.opentracing.Span deserialize(String str) throws JsonParseException, JsonMappingException, IOException {
|
||||
return objectMapper.readValue(str, DDSpan.class);
|
||||
public io.opentracing.Span deserialize(String str) throws Exception {
|
||||
throw new Exception("Deserialisation of spans is not implemented yet");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
Tracer tracer = new Tracer();
|
||||
io.opentracing.Span span = tracer.buildSpan("Hello!")
|
||||
Span span = tracer.buildSpan("Hello!")
|
||||
.withTag("port", 1234)
|
||||
.withTag("bool", true)
|
||||
.withTag("hello", "world")
|
||||
|
|
|
@ -27,7 +27,7 @@ public class Tracer implements io.opentracing.Tracer {
|
|||
public class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {
|
||||
|
||||
private final String operationName;
|
||||
private Map<String, Object> tags = new HashMap<>();
|
||||
private Map<String, Object> tags = new HashMap<String,Object>();
|
||||
private Long timestamp;
|
||||
private SpanContext parent;
|
||||
private String serviceName;
|
||||
|
@ -39,16 +39,16 @@ public class Tracer implements io.opentracing.Tracer {
|
|||
this.operationName = operationName;
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder asChildOf(SpanContext spanContext) {
|
||||
public Tracer.SpanBuilder asChildOf(SpanContext spanContext) {
|
||||
this.parent = spanContext;
|
||||
return this;
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder asChildOf(Span span) {
|
||||
public Tracer.SpanBuilder asChildOf(Span span) {
|
||||
return asChildOf(span.context());
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder addReference(String referenceType, SpanContext spanContext) {
|
||||
public Tracer.SpanBuilder addReference(String referenceType, SpanContext spanContext) {
|
||||
|
||||
if (References.CHILD_OF.equals(referenceType) || References.FOLLOWS_FROM.equals(referenceType)) {
|
||||
// @todo: implements the notion of referenceType, currently only link a span to a parent one
|
||||
|
@ -59,24 +59,24 @@ public class Tracer implements io.opentracing.Tracer {
|
|||
}
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder withTag(String tag, Number number) {
|
||||
public Tracer.SpanBuilder withTag(String tag, Number number) {
|
||||
return withTag(tag, (Object) number);
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder withTag(String tag, String string) {
|
||||
public Tracer.SpanBuilder withTag(String tag, String string) {
|
||||
return withTag(tag, (Object) string);
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder withTag(String tag, boolean bool) {
|
||||
public Tracer.SpanBuilder withTag(String tag, boolean bool) {
|
||||
return withTag(tag, (Object) bool);
|
||||
}
|
||||
|
||||
private io.opentracing.Tracer.SpanBuilder withTag(String tag, Object value) {
|
||||
private Tracer.SpanBuilder withTag(String tag, Object value) {
|
||||
this.tags.put(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public io.opentracing.Tracer.SpanBuilder withStartTimestamp(long timestamp) {
|
||||
public Tracer.SpanBuilder withStartTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
@ -109,7 +109,6 @@ public class Tracer implements io.opentracing.Tracer {
|
|||
// build the context
|
||||
DDSpanContext context = buildTheSpanContext();
|
||||
|
||||
|
||||
return new DDSpan(
|
||||
Tracer.this,
|
||||
this.operationName,
|
||||
|
|
|
@ -5,8 +5,12 @@ import java.io.OutputStreamWriter;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.datadoghq.trace.impl.DDSpanSerializer;
|
||||
import com.datadoghq.trace.impl.Tracer;
|
||||
|
||||
import io.opentracing.Span;
|
||||
|
||||
public class DDApi {
|
||||
|
@ -36,9 +40,10 @@ public class DDApi {
|
|||
}
|
||||
|
||||
private int callPUT(String endpoint,String content){
|
||||
HttpURLConnection httpCon = null;
|
||||
try {
|
||||
URL url = new URL(tracesEndpoint);
|
||||
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
|
||||
httpCon = (HttpURLConnection) url.openConnection();
|
||||
httpCon.setDoOutput(true);
|
||||
httpCon.setRequestMethod("PUT");
|
||||
httpCon.setRequestProperty("Content-Type", "application/json");
|
||||
|
@ -54,6 +59,37 @@ public class DDApi {
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
Tracer tracer = new Tracer();
|
||||
List<Span> array = new ArrayList<Span>();
|
||||
Span span = tracer.buildSpan("Hello!")
|
||||
// .withTag("port", 1234)
|
||||
// .withTag("bool", true)
|
||||
.withTag("hello", "world")
|
||||
.start();
|
||||
array.add(span);
|
||||
|
||||
Span span2 = tracer.buildSpan("Hello2!")
|
||||
// .withTag("port", 1234)
|
||||
// .withTag("bool", true)
|
||||
.withTag("hello", "world")
|
||||
.start();
|
||||
array.add(span2);
|
||||
|
||||
DDSpanSerializer ddSpanSerializer = new DDSpanSerializer();
|
||||
|
||||
|
||||
|
||||
String str = ddSpanSerializer.serialize(array);
|
||||
str = "["+str+"]";
|
||||
|
||||
DDApi api = new DDApi(DDAgentWriter.DEFAULT_HOSTNAME, DDAgentWriter.DEFAULT_PORT);
|
||||
int status = api.callPUT(api.tracesEndpoint, str);
|
||||
System.out.println("Status: "+status);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,8 +187,8 @@ public class DDSpanBuilderTest {
|
|||
|
||||
assertThat(span.getOperationName()).isEqualTo(expectedName);
|
||||
assertThat(span.getBaggageItem(expectedBaggageItemKey)).isEqualTo(expectedBaggageItemValue);
|
||||
assertThat(span.DDContext().getServiceName()).isEqualTo(expectedServiceName);
|
||||
assertThat(span.DDContext().getResourceName()).isNotEqualTo(expectedResourceName);
|
||||
assertThat(((DDSpanContext) span.context()).getServiceName()).isEqualTo(expectedServiceName);
|
||||
assertThat(((DDSpan) span.context()).getResourceName()).isNotEqualTo(expectedResourceName);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue