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.DDTraceInfo',
|
||||
'com.datadoghq.trace.util.Clock',
|
||||
|
||||
]
|
||||
|
||||
dependencies {
|
||||
|
@ -29,6 +28,7 @@ dependencies {
|
|||
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: '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'
|
||||
|
||||
|
|
|
@ -3,16 +3,15 @@ package com.datadoghq.trace.writer;
|
|||
import com.datadoghq.trace.DDBaseSpan;
|
||||
import com.datadoghq.trace.DDTraceInfo;
|
||||
import com.datadoghq.trace.Service;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||
|
||||
/** The API pointing to a DD agent */
|
||||
@Slf4j
|
||||
|
@ -24,8 +23,7 @@ public class DDApi {
|
|||
private final String tracesEndpoint;
|
||||
private final String servicesEndpoint;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final JsonFactory jsonFactory = objectMapper.getFactory();
|
||||
private final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||
|
||||
public DDApi(final String host, final int port) {
|
||||
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
|
||||
|
@ -72,7 +70,6 @@ public class DDApi {
|
|||
/**
|
||||
* PUT to an endpoint the provided JSON content
|
||||
*
|
||||
* @param endpoint
|
||||
* @param content
|
||||
* @return the status code
|
||||
*/
|
||||
|
@ -86,11 +83,10 @@ public class DDApi {
|
|||
}
|
||||
|
||||
try {
|
||||
final OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
|
||||
final JsonGenerator jsonGen = jsonFactory.createGenerator(out);
|
||||
objectMapper.writeValue(jsonGen, content);
|
||||
jsonGen.flush();
|
||||
jsonGen.close();
|
||||
final OutputStream out = httpCon.getOutputStream();
|
||||
objectMapper.writeValue(out, content);
|
||||
out.flush();
|
||||
out.close();
|
||||
final int responseCode = httpCon.getResponseCode();
|
||||
if (responseCode == 200) {
|
||||
log.debug("Sent the payload to the DD agent.");
|
||||
|
@ -113,7 +109,7 @@ public class DDApi {
|
|||
httpCon = (HttpURLConnection) url.openConnection();
|
||||
httpCon.setDoOutput(true);
|
||||
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-Version", DDTraceInfo.JAVA_VERSION);
|
||||
httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
|
||||
|
|
Loading…
Reference in New Issue