Change Json for MsgPack
This commit is contained in:
parent
f564161454
commit
6392999f97
|
@ -16,7 +16,6 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
|
||||||
'com.datadoghq.trace.DDTags',
|
'com.datadoghq.trace.DDTags',
|
||||||
'com.datadoghq.trace.DDTraceInfo',
|
'com.datadoghq.trace.DDTraceInfo',
|
||||||
'com.datadoghq.trace.util.Clock',
|
'com.datadoghq.trace.util.Clock',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -29,6 +28,7 @@ dependencies {
|
||||||
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.8.8'
|
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.8.8'
|
||||||
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
|
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
|
||||||
compile group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc3'
|
compile group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc3'
|
||||||
|
compile group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.13'
|
||||||
|
|
||||||
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,15 @@ package com.datadoghq.trace.writer;
|
||||||
import com.datadoghq.trace.DDBaseSpan;
|
import com.datadoghq.trace.DDBaseSpan;
|
||||||
import com.datadoghq.trace.DDTraceInfo;
|
import com.datadoghq.trace.DDTraceInfo;
|
||||||
import com.datadoghq.trace.Service;
|
import com.datadoghq.trace.Service;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||||
|
|
||||||
/** The API pointing to a DD agent */
|
/** The API pointing to a DD agent */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -24,8 +23,7 @@ public class DDApi {
|
||||||
private final String tracesEndpoint;
|
private final String tracesEndpoint;
|
||||||
private final String servicesEndpoint;
|
private final String servicesEndpoint;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||||
private final JsonFactory jsonFactory = objectMapper.getFactory();
|
|
||||||
|
|
||||||
public DDApi(final String host, final int port) {
|
public DDApi(final String host, final int port) {
|
||||||
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
|
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
|
||||||
|
@ -72,7 +70,6 @@ public class DDApi {
|
||||||
/**
|
/**
|
||||||
* PUT to an endpoint the provided JSON content
|
* PUT to an endpoint the provided JSON content
|
||||||
*
|
*
|
||||||
* @param endpoint
|
|
||||||
* @param content
|
* @param content
|
||||||
* @return the status code
|
* @return the status code
|
||||||
*/
|
*/
|
||||||
|
@ -86,11 +83,10 @@ public class DDApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
|
final OutputStream out = httpCon.getOutputStream();
|
||||||
final JsonGenerator jsonGen = jsonFactory.createGenerator(out);
|
objectMapper.writeValue(out, content);
|
||||||
objectMapper.writeValue(jsonGen, content);
|
out.flush();
|
||||||
jsonGen.flush();
|
out.close();
|
||||||
jsonGen.close();
|
|
||||||
final int responseCode = httpCon.getResponseCode();
|
final int responseCode = httpCon.getResponseCode();
|
||||||
if (responseCode == 200) {
|
if (responseCode == 200) {
|
||||||
log.debug("Sent the payload to the DD agent.");
|
log.debug("Sent the payload to the DD agent.");
|
||||||
|
@ -113,7 +109,7 @@ public class DDApi {
|
||||||
httpCon = (HttpURLConnection) url.openConnection();
|
httpCon = (HttpURLConnection) url.openConnection();
|
||||||
httpCon.setDoOutput(true);
|
httpCon.setDoOutput(true);
|
||||||
httpCon.setRequestMethod("PUT");
|
httpCon.setRequestMethod("PUT");
|
||||||
httpCon.setRequestProperty("Content-Type", "application/json");
|
httpCon.setRequestProperty("Content-Type", "application/msgpack");
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
|
httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTraceInfo.JAVA_VERSION);
|
httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTraceInfo.JAVA_VERSION);
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
|
httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
|
||||||
|
|
Loading…
Reference in New Issue