Merge pull request #307 from DataDog/tyler/remove-guava-dep
Remove dependency on guava for dd-trace-ot
This commit is contained in:
commit
26d36287c2
|
@ -27,15 +27,17 @@ testSets {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile deps.autoservice
|
||||||
|
|
||||||
compile project(':dd-trace-api')
|
compile project(':dd-trace-api')
|
||||||
compile deps.opentracing
|
compile deps.opentracing
|
||||||
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: '0.1.0'
|
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: '0.1.0'
|
||||||
|
|
||||||
compile deps.jackson
|
compile deps.jackson
|
||||||
compile deps.slf4j
|
compile deps.slf4j
|
||||||
compile deps.autoservice
|
|
||||||
compile group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.2'
|
compile group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.2'
|
||||||
|
|
||||||
|
testCompile deps.autoservice
|
||||||
testCompile group: 'org.objenesis', name: 'objenesis', version: '2.6'
|
testCompile group: 'org.objenesis', name: 'objenesis', version: '2.6'
|
||||||
testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.5'
|
testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.5'
|
||||||
testCompile 'com.github.stefanbirkner:system-rules:1.17.1'
|
testCompile 'com.github.stefanbirkner:system-rules:1.17.1'
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package datadog.opentracing;
|
package datadog.opentracing;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import datadog.opentracing.decorators.AbstractDecorator;
|
import datadog.opentracing.decorators.AbstractDecorator;
|
||||||
import datadog.opentracing.decorators.DDDecoratorsFactory;
|
import datadog.opentracing.decorators.DDDecoratorsFactory;
|
||||||
import datadog.opentracing.propagation.Codec;
|
import datadog.opentracing.propagation.Codec;
|
||||||
|
@ -244,13 +242,13 @@ public class DDTracer implements io.opentracing.Tracer {
|
||||||
}
|
}
|
||||||
final ArrayList<DDSpan> writtenTrace;
|
final ArrayList<DDSpan> writtenTrace;
|
||||||
if (interceptors.isEmpty()) {
|
if (interceptors.isEmpty()) {
|
||||||
writtenTrace = Lists.newArrayList(trace);
|
writtenTrace = new ArrayList<>(trace);
|
||||||
} else {
|
} else {
|
||||||
Collection<? extends MutableSpan> interceptedTrace = Lists.newArrayList(trace);
|
Collection<? extends MutableSpan> interceptedTrace = new ArrayList<>(trace);
|
||||||
for (final TraceInterceptor interceptor : interceptors) {
|
for (final TraceInterceptor interceptor : interceptors) {
|
||||||
interceptedTrace = interceptor.onTraceComplete(interceptedTrace);
|
interceptedTrace = interceptor.onTraceComplete(interceptedTrace);
|
||||||
}
|
}
|
||||||
writtenTrace = Lists.newArrayListWithExpectedSize(interceptedTrace.size());
|
writtenTrace = new ArrayList<>(interceptedTrace.size());
|
||||||
for (final MutableSpan span : interceptedTrace) {
|
for (final MutableSpan span : interceptedTrace) {
|
||||||
if (span instanceof DDSpan) {
|
if (span instanceof DDSpan) {
|
||||||
writtenTrace.add((DDSpan) span);
|
writtenTrace.add((DDSpan) span);
|
||||||
|
@ -304,7 +302,7 @@ public class DDTracer implements io.opentracing.Tracer {
|
||||||
|
|
||||||
// Builder attributes
|
// Builder attributes
|
||||||
private Map<String, Object> tags =
|
private Map<String, Object> tags =
|
||||||
spanTags.isEmpty() ? Collections.<String, Object>emptyMap() : Maps.newHashMap(spanTags);
|
spanTags.isEmpty() ? Collections.<String, Object>emptyMap() : new HashMap<>(spanTags);
|
||||||
private long timestampMicro;
|
private long timestampMicro;
|
||||||
private SpanContext parent;
|
private SpanContext parent;
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
@ -429,7 +427,7 @@ public class DDTracer implements io.opentracing.Tracer {
|
||||||
// Private methods
|
// Private methods
|
||||||
private DDSpanBuilder withTag(final String tag, final Object value) {
|
private DDSpanBuilder withTag(final String tag, final Object value) {
|
||||||
if (this.tags.isEmpty()) {
|
if (this.tags.isEmpty()) {
|
||||||
this.tags = Maps.newHashMap();
|
this.tags = new HashMap<>();
|
||||||
}
|
}
|
||||||
this.tags.put(tag, value);
|
this.tags.put(tag, value);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package datadog.opentracing;
|
package datadog.opentracing;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
import datadog.opentracing.scopemanager.ContinuableScope;
|
import datadog.opentracing.scopemanager.ContinuableScope;
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.ReferenceQueue;
|
import java.lang.ref.ReferenceQueue;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -26,7 +26,8 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
private final long traceId;
|
private final long traceId;
|
||||||
|
|
||||||
private final ReferenceQueue referenceQueue = new ReferenceQueue();
|
private final ReferenceQueue referenceQueue = new ReferenceQueue();
|
||||||
private final Set<WeakReference<?>> weakReferences = Sets.newConcurrentHashSet();
|
private final Set<WeakReference<?>> weakReferences =
|
||||||
|
Collections.newSetFromMap(new ConcurrentHashMap<WeakReference<?>, Boolean>());
|
||||||
|
|
||||||
private final AtomicInteger pendingReferenceCount = new AtomicInteger(0);
|
private final AtomicInteger pendingReferenceCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
@ -172,12 +173,20 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
private static class SpanCleaner implements Runnable {
|
private static class SpanCleaner implements Runnable {
|
||||||
private static final long CLEAN_FREQUENCY = 1;
|
private static final long CLEAN_FREQUENCY = 1;
|
||||||
private static final ThreadFactory FACTORY =
|
private static final ThreadFactory FACTORY =
|
||||||
new ThreadFactoryBuilder().setNameFormat("dd-span-cleaner-%d").setDaemon(true).build();
|
new ThreadFactory() {
|
||||||
|
@Override
|
||||||
|
public Thread newThread(final Runnable r) {
|
||||||
|
final Thread thread = new Thread(r, "dd-span-cleaner");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final ScheduledExecutorService EXECUTOR_SERVICE =
|
private static final ScheduledExecutorService EXECUTOR_SERVICE =
|
||||||
Executors.newScheduledThreadPool(1, FACTORY);
|
Executors.newScheduledThreadPool(1, FACTORY);
|
||||||
|
|
||||||
static final Set<PendingTrace> pendingTraces = Sets.newConcurrentHashSet();
|
static final Set<PendingTrace> pendingTraces =
|
||||||
|
Collections.newSetFromMap(new ConcurrentHashMap<PendingTrace, Boolean>());
|
||||||
|
|
||||||
static void start() {
|
static void start() {
|
||||||
EXECUTOR_SERVICE.scheduleAtFixedRate(new SpanCleaner(), 0, CLEAN_FREQUENCY, TimeUnit.SECONDS);
|
EXECUTOR_SERVICE.scheduleAtFixedRate(new SpanCleaner(), 0, CLEAN_FREQUENCY, TimeUnit.SECONDS);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package datadog.trace.common;
|
package datadog.trace.common;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import datadog.opentracing.DDTracer;
|
import datadog.opentracing.DDTracer;
|
||||||
import datadog.trace.common.writer.DDAgentWriter;
|
import datadog.trace.common.writer.DDAgentWriter;
|
||||||
import datadog.trace.common.writer.Writer;
|
import datadog.trace.common.writer.Writer;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -84,7 +84,7 @@ public class DDTraceConfig extends Properties {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] tokens = str.split(",");
|
final String[] tokens = str.split(",");
|
||||||
final Map<String, Object> map = Maps.newHashMapWithExpectedSize(tokens.length);
|
final Map<String, Object> map = new HashMap<>(tokens.length + 1, 1f);
|
||||||
|
|
||||||
for (final String token : tokens) {
|
for (final String token : tokens) {
|
||||||
final String[] keyValue = token.split(":");
|
final String[] keyValue = token.split(":");
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package datadog.trace.common.writer;
|
package datadog.trace.common.writer;
|
||||||
|
|
||||||
import com.google.auto.service.AutoService;
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
import datadog.opentracing.DDSpan;
|
import datadog.opentracing.DDSpan;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -25,7 +23,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
* spans.
|
* spans.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AutoService(Writer.class)
|
|
||||||
public class DDAgentWriter implements Writer {
|
public class DDAgentWriter implements Writer {
|
||||||
|
|
||||||
/** Default location of the DD agent */
|
/** Default location of the DD agent */
|
||||||
|
@ -43,7 +40,14 @@ public class DDAgentWriter implements Writer {
|
||||||
static final long FLUSH_TIME_SECONDS = 1;
|
static final long FLUSH_TIME_SECONDS = 1;
|
||||||
|
|
||||||
private final ThreadFactory agentWriterThreadFactory =
|
private final ThreadFactory agentWriterThreadFactory =
|
||||||
new ThreadFactoryBuilder().setNameFormat("dd-agent-writer-%d").setDaemon(true).build();
|
new ThreadFactory() {
|
||||||
|
@Override
|
||||||
|
public Thread newThread(final Runnable r) {
|
||||||
|
final Thread thread = new Thread(r, "dd-agent-writer");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** Scheduled thread pool, acting like a cron */
|
/** Scheduled thread pool, acting like a cron */
|
||||||
private final ScheduledExecutorService scheduledExecutor =
|
private final ScheduledExecutorService scheduledExecutor =
|
||||||
|
|
|
@ -2,7 +2,6 @@ package datadog.trace.common.writer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.util.concurrent.RateLimiter;
|
|
||||||
import datadog.opentracing.DDSpan;
|
import datadog.opentracing.DDSpan;
|
||||||
import datadog.opentracing.DDTraceOTInfo;
|
import datadog.opentracing.DDTraceOTInfo;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -30,15 +29,13 @@ public class DDApi {
|
||||||
|
|
||||||
private static final String TRACES_ENDPOINT_V3 = "/v0.3/traces";
|
private static final String TRACES_ENDPOINT_V3 = "/v0.3/traces";
|
||||||
private static final String TRACES_ENDPOINT_V4 = "/v0.4/traces";
|
private static final String TRACES_ENDPOINT_V4 = "/v0.4/traces";
|
||||||
private static final long SECONDS_BETWEEN_ERROR_LOG = TimeUnit.MINUTES.toSeconds(5);
|
private static final long MILLISECONDS_BETWEEN_ERROR_LOG = TimeUnit.MINUTES.toMillis(5);
|
||||||
|
|
||||||
private final String tracesEndpoint;
|
private final String tracesEndpoint;
|
||||||
private final List<ResponseListener> responseListeners = new ArrayList<>();
|
private final List<ResponseListener> responseListeners = new ArrayList<>();
|
||||||
|
|
||||||
private AtomicInteger traceCount;
|
private AtomicInteger traceCount;
|
||||||
|
private volatile long nextAllowedLogTime = 0;
|
||||||
private final RateLimiter loggingRateLimiter =
|
|
||||||
RateLimiter.create(1.0 / SECONDS_BETWEEN_ERROR_LOG);
|
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
private static final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||||
|
|
||||||
|
@ -106,14 +103,15 @@ public class DDApi {
|
||||||
totalSize,
|
totalSize,
|
||||||
responseCode,
|
responseCode,
|
||||||
httpCon.getResponseMessage());
|
httpCon.getResponseMessage());
|
||||||
} else if (loggingRateLimiter.tryAcquire()) {
|
} else if (nextAllowedLogTime < System.currentTimeMillis()) {
|
||||||
|
nextAllowedLogTime = System.currentTimeMillis() + MILLISECONDS_BETWEEN_ERROR_LOG;
|
||||||
log.warn(
|
log.warn(
|
||||||
"Error while sending {} of {} traces to the DD agent. Status: {} (going silent for {} seconds)",
|
"Error while sending {} of {} traces to the DD agent. Status: {} (going silent for {} seconds)",
|
||||||
traces.size(),
|
traces.size(),
|
||||||
totalSize,
|
totalSize,
|
||||||
responseCode,
|
responseCode,
|
||||||
httpCon.getResponseMessage(),
|
httpCon.getResponseMessage(),
|
||||||
SECONDS_BETWEEN_ERROR_LOG);
|
TimeUnit.MILLISECONDS.toMinutes(MILLISECONDS_BETWEEN_ERROR_LOG));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -143,14 +141,15 @@ public class DDApi {
|
||||||
+ totalSize
|
+ totalSize
|
||||||
+ " traces to the DD agent.",
|
+ " traces to the DD agent.",
|
||||||
e);
|
e);
|
||||||
} else if (loggingRateLimiter.tryAcquire()) {
|
} else if (nextAllowedLogTime < System.currentTimeMillis()) {
|
||||||
|
nextAllowedLogTime = System.currentTimeMillis() + MILLISECONDS_BETWEEN_ERROR_LOG;
|
||||||
log.warn(
|
log.warn(
|
||||||
"Error while sending {} of {} traces to the DD agent. {}: {} (going silent for {} seconds)",
|
"Error while sending {} of {} traces to the DD agent. {}: {} (going silent for {} minutes)",
|
||||||
traces.size(),
|
traces.size(),
|
||||||
totalSize,
|
totalSize,
|
||||||
e.getClass().getName(),
|
e.getClass().getName(),
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
SECONDS_BETWEEN_ERROR_LOG);
|
TimeUnit.MILLISECONDS.toMinutes(MILLISECONDS_BETWEEN_ERROR_LOG));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package datadog.trace.common.writer;
|
package datadog.trace.common.writer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.auto.service.AutoService;
|
|
||||||
import datadog.opentracing.DDSpan;
|
import datadog.opentracing.DDSpan;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AutoService(Writer.class)
|
|
||||||
public class LoggingWriter implements Writer {
|
public class LoggingWriter implements Writer {
|
||||||
private final ObjectMapper serializer = new ObjectMapper();
|
private final ObjectMapper serializer = new ObjectMapper();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue