Apply suggestions from CR #827

This commit is contained in:
Luca Abbati 2019-05-17 10:15:03 +02:00
parent 1d5dd5b28a
commit ad3401b815
No known key found for this signature in database
GPG Key ID: C901DDA2FFE14529
9 changed files with 40 additions and 45 deletions

View File

@ -20,8 +20,8 @@ Other source files (Groovy, Scala, etc) should ideally be formatted by Intellij
Suggested plugins and settings:
* Editor > Code Style > Java/Groovy > Imports
* Class count to use import with '*': `10` (some number sufficiently large that is unlikely to matter)
* Names count to use static import with '*': `10`
* Class count to use import with '*': `50` (some number sufficiently large that is unlikely to matter)
* Names count to use static import with '*': `50`
* With java use the following import layout (groovy should still use the default) to ensure consistency with google-java-format:
![import layout](https://user-images.githubusercontent.com/734411/43430811-28442636-94ae-11e8-86f1-f270ddcba023.png)
* [Google Java Format](https://plugins.jetbrains.com/plugin/8527-google-java-format)

View File

@ -320,8 +320,8 @@ public class Config {
log.debug("New instance: {}", this);
}
/** @return A map of tags to be applied only to the currently tracing application root span. */
public Map<String, String> getApplicationRootSpanTags() {
/** @return A map of tags to be applied only to the local application root span. */
public Map<String, String> getLocalRootSpanTags() {
final Map<String, String> result = newHashMap(reportHostName ? 1 : 0);
result.putAll(getRuntimeTags());
if (reportHostName) {

View File

@ -50,7 +50,7 @@ public interface MutableSpan {
MutableSpan setError(boolean value);
/** @deprecated Use {@link #getApplicationRootSpan()} instead. */
/** @deprecated Use {@link #getLocalRootSpan()} instead. */
@Deprecated
MutableSpan getRootSpan();
@ -59,7 +59,7 @@ public interface MutableSpan {
* this method returns the root span only for the fragment generated by the currently traced
* application.
*
* @return The root span for current the trace fragment.
* @return The root span for the current trace fragment.
*/
MutableSpan getApplicationRootSpan();
MutableSpan getLocalRootSpan();
}

View File

@ -667,7 +667,7 @@ class ConfigTest extends Specification {
def config = Config.get(properties)
then:
!config.applicationRootSpanTags.containsKey('_dd.hostname')
!config.localRootSpanTags.containsKey('_dd.hostname')
}
def "verify configuration to add hostname to root span tags"() {
@ -679,6 +679,6 @@ class ConfigTest extends Specification {
def config = Config.get(properties)
then:
config.applicationRootSpanTags.get('_dd.hostname') == InetAddress.localHost.hostName
config.localRootSpanTags.get('_dd.hostname') == InetAddress.localHost.hostName
}
}

View File

@ -121,22 +121,10 @@ public class DDSpan implements Span, MutableSpan {
* the context of distributed tracing this will return true if an only if this is the application
* initializing the trace.
*
* @deprecated Use {@link #isTraceRootSpan()} instead.
* @return true if root, false otherwise
*/
@JsonIgnore
@Deprecated
public final boolean isRootSpan() {
return isTraceRootSpan();
}
/**
* Returns whether or not this is the root span of the entire trace. In the context of distributed
* tracing, when the currently traced application did not initialize the trace then this will
* always be false.
*/
@JsonIgnore
public final boolean isTraceRootSpan() {
return "0".equals(context.getParentId());
}
@ -144,12 +132,12 @@ public class DDSpan implements Span, MutableSpan {
@Deprecated
@JsonIgnore
public MutableSpan getRootSpan() {
return getApplicationRootSpan();
return getLocalRootSpan();
}
@Override
@JsonIgnore
public MutableSpan getApplicationRootSpan() {
public MutableSpan getLocalRootSpan() {
return context().getTrace().getRootSpan();
}

View File

@ -26,7 +26,17 @@ import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import java.io.Closeable;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.SortedSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ThreadLocalRandom;
@ -47,7 +57,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
final ContextualScopeManager scopeManager = new ContextualScopeManager();
/** A set of tags that are added only to the application's root span */
private final Map<String, String> applicationRootSpanTags;
private final Map<String, String> localRootSpanTags;
/** A set of tags that are added to every span */
private final Map<String, String> defaultSpanTags;
/** A configured mapping of service names to update with new values */
@ -97,7 +107,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
// This constructor is already used in the wild, so we have to keep it inside this API for now.
public DDTracer(final String serviceName, final Writer writer, final Sampler sampler) {
this(serviceName, writer, sampler, Config.get().getApplicationRootSpanTags());
this(serviceName, writer, sampler, Config.get().getLocalRootSpanTags());
}
private DDTracer(final String serviceName, final Config config) {
@ -105,7 +115,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
serviceName,
Writer.Builder.forConfig(config),
Sampler.Builder.forConfig(config),
config.getApplicationRootSpanTags(),
config.getLocalRootSpanTags(),
config.getMergedSpanTags(),
config.getServiceMapping(),
config.getHeaderTags(),
@ -139,7 +149,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
config.getServiceName(),
writer,
Sampler.Builder.forConfig(config),
config.getApplicationRootSpanTags(),
config.getLocalRootSpanTags(),
config.getMergedSpanTags(),
config.getServiceMapping(),
config.getHeaderTags(),
@ -155,7 +165,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
final Writer writer,
final Sampler sampler,
final String runtimeId,
final Map<String, String> applicationRootSpanTags,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags,
final Map<String, String> serviceNameMappings,
final Map<String, String> taggedHeaders) {
@ -163,7 +173,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
serviceName,
writer,
sampler,
customRuntimeTags(runtimeId, applicationRootSpanTags),
customRuntimeTags(runtimeId, localRootSpanTags),
defaultSpanTags,
serviceNameMappings,
taggedHeaders,
@ -178,7 +188,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
final String serviceName,
final Writer writer,
final Sampler sampler,
final Map<String, String> applicationRootSpanTags,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags,
final Map<String, String> serviceNameMappings,
final Map<String, String> taggedHeaders) {
@ -186,7 +196,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
serviceName,
writer,
sampler,
applicationRootSpanTags,
localRootSpanTags,
defaultSpanTags,
serviceNameMappings,
taggedHeaders,
@ -197,12 +207,12 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
final String serviceName,
final Writer writer,
final Sampler sampler,
final Map<String, String> applicationRootSpanTags,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags,
final Map<String, String> serviceNameMappings,
final Map<String, String> taggedHeaders,
final int partialFlushMinSpans) {
assert applicationRootSpanTags != null;
assert localRootSpanTags != null;
assert defaultSpanTags != null;
assert serviceNameMappings != null;
assert taggedHeaders != null;
@ -211,7 +221,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
this.writer = writer;
this.writer.start();
this.sampler = sampler;
this.applicationRootSpanTags = applicationRootSpanTags;
this.localRootSpanTags = localRootSpanTags;
this.defaultSpanTags = defaultSpanTags;
this.serviceNameMappings = serviceNameMappings;
this.partialFlushMinSpans = partialFlushMinSpans;
@ -653,7 +663,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
origin = null;
}
tags.putAll(applicationRootSpanTags);
tags.putAll(localRootSpanTags);
parentTrace = new PendingTrace(DDTracer.this, traceId, serviceNameMappings);
}

View File

@ -32,7 +32,7 @@ public class RateByServiceSampler implements Sampler, ResponseListener {
/** If span is a root span, set the span context samplingPriority to keep or drop */
public void initializeSamplingPriority(DDSpan span) {
if (span.isTraceRootSpan()) {
if (span.isRootSpan()) {
// Run the priority sampler on the new span
setSamplingPriorityOnSpanContext(span);
} else if (span.getSamplingPriority() == null) {

View File

@ -208,15 +208,12 @@ class DDSpanTest extends Specification {
new ExtractedContext("1", "2", 0, "some-origin", [:], [:]) | _
}
def "isTraceRootSpan() in and not in the context of distributed tracing"() {
def "isRootSpan() in and not in the context of distributed tracing"() {
setup:
def root = tracer.buildSpan("root").asChildOf((SpanContext)extractedContext).start()
def child = tracer.buildSpan("child").asChildOf(root).start()
expect:
root.isTraceRootSpan() == isTraceRootSpan
!child.isTraceRootSpan()
// Checking for backward compatibility method names
root.isRootSpan() == isTraceRootSpan
!child.isRootSpan()
@ -236,8 +233,8 @@ class DDSpanTest extends Specification {
def child = tracer.buildSpan("child").asChildOf(root).start()
expect:
root.applicationRootSpan == root
child.applicationRootSpan == root
root.localRootSpan == root
child.localRootSpan == root
// Checking for backward compatibility method names
root.rootSpan == root
child.rootSpan == root

View File

@ -126,8 +126,8 @@ class DDTracerTest extends Specification {
tracer.serviceName == DEFAULT_SERVICE_NAME
tracer.sampler == sampler
tracer.writer == writer
tracer.applicationRootSpanTags[Config.RUNTIME_ID_TAG].size() > 0 // not null or empty
tracer.applicationRootSpanTags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
tracer.localRootSpanTags[Config.RUNTIME_ID_TAG].size() > 0 // not null or empty
tracer.localRootSpanTags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
}
def "Shares TraceCount with DDApi with #key = #value"() {