adding meta support
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -22,6 +22,9 @@ import java.util.*;
*/
public class DDTracer implements io.opentracing.Tracer {
+ public final static String CURRENT_VERSION = DDTracer.class.getPackage().getImplementationVersion();
+ public final static String JAVA_VERSION = System.getProperty("java.version", "unknown");
+
/**
* Writer is an charge of reporting traces and spans to the desired endpoint
*/

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/writer/DDApi.java
dd-trace/src/main/java/com/datadoghq/trace/writer/DDApi.java
package com.datadoghq.trace.writer;
-import java.io.OutputStreamWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.datadoghq.trace.DDBaseSpan;
+import com.datadoghq.trace.DDTracer;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
/**
* The API pointing to a DD agent
@@ -20,18 +21,16 @@ public class DDApi {
private static final Logger logger = LoggerFactory.getLogger(DDApi.class.getName());
+
private static final String TRACES_ENDPOINT = "/v0.3/traces";
-// private static final String SERVICES_ENDPOINT = "/v0.3/services";
private final String tracesEndpoint;
-// private final String servicesEndpoint;
private final ObjectMapper objectMapper = new ObjectMapper();
private final JsonFactory jsonFactory = objectMapper.getFactory();
public DDApi(String host, int port) {
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
-// this.servicesEndpoint = "http://" + host + ":" + port + SERVICES_ENDPOINT;
}
/**
@@ -41,7 +40,7 @@ public class DDApi {
* @return the staus code returned
*/
public boolean sendTraces(List<List<DDBaseSpan<?>>> traces) {
- int status = callPUT(tracesEndpoint, traces);
+ int status = callPUT(traces);
if (status == 200) {
logger.debug("Succesfully sent {} traces to the DD agent.", traces.size());
return true;
@@ -58,14 +57,10 @@ public class DDApi {
* @param content
* @return the status code
*/
- private int callPUT(String endpoint, Object content) {
+ private int callPUT(Object content) {
HttpURLConnection httpCon = null;
try {
- URL url = new URL(endpoint);
- httpCon = (HttpURLConnection) url.openConnection();
- httpCon.setDoOutput(true);
- httpCon.setRequestMethod("PUT");
- httpCon.setRequestProperty("Content-Type", "application/json");
+ httpCon = getHttpURLConnection();
} catch (Exception e) {
logger.warn("Error thrown before PUT call to the DD agent.", e);
return -1;
@@ -90,4 +85,17 @@ public class DDApi {
}
}
+ private HttpURLConnection getHttpURLConnection() throws IOException {
+ HttpURLConnection httpCon;
+ URL url = new URL(tracesEndpoint);
+ httpCon = (HttpURLConnection) url.openConnection();
+ httpCon.setDoOutput(true);
+ httpCon.setRequestMethod("PUT");
+ httpCon.setRequestProperty("Content-Type", "application/json");
+ httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
+ httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTracer.JAVA_VERSION);
+ httpCon.setRequestProperty("Datadog-Meta-Tracer-Version", DDTracer.CURRENT_VERSION);
+ return httpCon;
+ }
+
}

adding meta support