Remove dependency on guava for dd-trace-ot
MODIFY
dd-trace-ot/dd-trace-ot.gradle
dd-trace-ot/dd-trace-ot.gradle
@@ -27,15 +27,17 @@ testSets {
}
dependencies {
+ compile deps.autoservice
+
compile project(':dd-trace-api')
compile deps.opentracing
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: '0.1.0'
compile deps.jackson
compile deps.slf4j
- compile deps.autoservice
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: 'cglib', name: 'cglib-nodep', version: '3.2.5'
testCompile 'com.github.stefanbirkner:system-rules:1.17.1'

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
package datadog.opentracing;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import datadog.opentracing.decorators.AbstractDecorator;
import datadog.opentracing.decorators.DDDecoratorsFactory;
import datadog.opentracing.propagation.Codec;
@@ -244,13 +242,13 @@ public class DDTracer implements io.opentracing.Tracer {
}
final ArrayList<DDSpan> writtenTrace;
if (interceptors.isEmpty()) {
- writtenTrace = Lists.newArrayList(trace);
+ writtenTrace = new ArrayList<>(trace);
} else {
- Collection<? extends MutableSpan> interceptedTrace = Lists.newArrayList(trace);
+ Collection<? extends MutableSpan> interceptedTrace = new ArrayList<>(trace);
for (final TraceInterceptor interceptor : interceptors) {
interceptedTrace = interceptor.onTraceComplete(interceptedTrace);
}
- writtenTrace = Lists.newArrayListWithExpectedSize(interceptedTrace.size());
+ writtenTrace = new ArrayList<>(interceptedTrace.size());
for (final MutableSpan span : interceptedTrace) {
if (span instanceof DDSpan) {
writtenTrace.add((DDSpan) span);
@@ -304,7 +302,7 @@ public class DDTracer implements io.opentracing.Tracer {
// Builder attributes
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 SpanContext parent;
private String serviceName;
@@ -429,7 +427,7 @@ public class DDTracer implements io.opentracing.Tracer {
// Private methods
private DDSpanBuilder withTag(final String tag, final Object value) {
if (this.tags.isEmpty()) {
- this.tags = Maps.newHashMap();
+ this.tags = new HashMap<>();
}
this.tags.put(tag, value);
return this;

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/PendingTrace.java
dd-trace-ot/src/main/java/datadog/opentracing/PendingTrace.java
package datadog.opentracing;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
import datadog.opentracing.scopemanager.ContinuableScope;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
+import java.util.Collections;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -26,7 +26,8 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
private final long traceId;
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);
@@ -172,12 +173,20 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
private static class SpanCleaner implements Runnable {
private static final long CLEAN_FREQUENCY = 1;
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 =
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() {
EXECUTOR_SERVICE.scheduleAtFixedRate(new SpanCleaner(), 0, CLEAN_FREQUENCY, TimeUnit.SECONDS);

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/DDTraceConfig.java
dd-trace-ot/src/main/java/datadog/trace/common/DDTraceConfig.java
package datadog.trace.common;
-import com.google.common.collect.Maps;
import datadog.opentracing.DDTracer;
import datadog.trace.common.writer.DDAgentWriter;
import datadog.trace.common.writer.Writer;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
@@ -84,7 +84,7 @@ public class DDTraceConfig extends Properties {
}
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) {
final String[] keyValue = token.split(":");

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/writer/DDAgentWriter.java
dd-trace-ot/src/main/java/datadog/trace/common/writer/DDAgentWriter.java
package datadog.trace.common.writer;
-import com.google.auto.service.AutoService;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
import datadog.opentracing.DDSpan;
import java.util.List;
import java.util.concurrent.Callable;
@@ -25,7 +23,6 @@ import lombok.extern.slf4j.Slf4j;
* spans.
*/
@Slf4j
-@AutoService(Writer.class)
public class DDAgentWriter implements Writer {
/** Default location of the DD agent */
@@ -43,7 +40,14 @@ public class DDAgentWriter implements Writer {
static final long FLUSH_TIME_SECONDS = 1;
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 */
private final ScheduledExecutorService scheduledExecutor =

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/writer/DDApi.java
dd-trace-ot/src/main/java/datadog/trace/common/writer/DDApi.java
@@ -2,7 +2,6 @@ package datadog.trace.common.writer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.util.concurrent.RateLimiter;
import datadog.opentracing.DDSpan;
import datadog.opentracing.DDTraceOTInfo;
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_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 List<ResponseListener> responseListeners = new ArrayList<>();
private AtomicInteger traceCount;
-
- private final RateLimiter loggingRateLimiter =
- RateLimiter.create(1.0 / SECONDS_BETWEEN_ERROR_LOG);
+ private volatile long nextAllowedLogTime = 0;
private static final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
@@ -106,14 +103,15 @@ public class DDApi {
totalSize,
responseCode,
httpCon.getResponseMessage());
- } else if (loggingRateLimiter.tryAcquire()) {
+ } else if (nextAllowedLogTime < System.currentTimeMillis()) {
+ nextAllowedLogTime = System.currentTimeMillis() + MILLISECONDS_BETWEEN_ERROR_LOG;
log.warn(
"Error while sending {} of {} traces to the DD agent. Status: {} (going silent for {} seconds)",
traces.size(),
totalSize,
responseCode,
httpCon.getResponseMessage(),
- SECONDS_BETWEEN_ERROR_LOG);
+ TimeUnit.MILLISECONDS.toMinutes(MILLISECONDS_BETWEEN_ERROR_LOG));
}
return false;
}
@@ -143,14 +141,15 @@ public class DDApi {
+ totalSize
+ " traces to the DD agent.",
e);
- } else if (loggingRateLimiter.tryAcquire()) {
+ } else if (nextAllowedLogTime < System.currentTimeMillis()) {
+ nextAllowedLogTime = System.currentTimeMillis() + MILLISECONDS_BETWEEN_ERROR_LOG;
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(),
totalSize,
e.getClass().getName(),
e.getMessage(),
- SECONDS_BETWEEN_ERROR_LOG);
+ TimeUnit.MILLISECONDS.toMinutes(MILLISECONDS_BETWEEN_ERROR_LOG));
}
return false;
}

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/writer/LoggingWriter.java
dd-trace-ot/src/main/java/datadog/trace/common/writer/LoggingWriter.java
package datadog.trace.common.writer;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.auto.service.AutoService;
import datadog.opentracing.DDSpan;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@Slf4j
-@AutoService(Writer.class)
public class LoggingWriter implements Writer {
private final ObjectMapper serializer = new ObjectMapper();

Remove dependency on guava for dd-trace-ot