Skip to content

Commit

Permalink
Remove globally applied tags (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Dec 3, 2019
1 parent 0514c66 commit a4089ff
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 367 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.trace.agent.decorator;

import datadog.trace.api.Config;
import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;

Expand All @@ -10,7 +9,6 @@ public abstract class ServerDecorator extends BaseDecorator {
public AgentSpan afterStart(final AgentSpan span) {
assert span != null;
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
span.setTag(Config.LANGUAGE_TAG_KEY, Config.LANGUAGE_TAG_VALUE);
return super.afterStart(span);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package datadog.trace.agent.decorator

import datadog.trace.api.Config

import datadog.trace.api.DDTags
import datadog.trace.instrumentation.api.AgentSpan
import io.opentracing.tag.Tags
Expand All @@ -15,7 +15,6 @@ class ServerDecoratorTest extends BaseDecoratorTest {
decorator.afterStart(span)

then:
1 * span.setTag(Config.LANGUAGE_TAG_KEY, Config.LANGUAGE_TAG_VALUE)
1 * span.setTag(Tags.COMPONENT.key, "test-component")
1 * span.setTag(Tags.SPAN_KIND.key, "server")
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package datadog.trace.agent.test.asserts

import datadog.opentracing.DDSpan
import datadog.trace.api.Config
import datadog.trace.instrumentation.api.Tags
import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType

Expand Down Expand Up @@ -35,27 +33,9 @@ class TagsAssert {
def defaultTags(boolean distributedRootSpan = false) {
assertedTags.add("thread.name")
assertedTags.add("thread.id")
assertedTags.add(Config.RUNTIME_ID_TAG)
assertedTags.add(Config.LANGUAGE_TAG_KEY)

assert tags["thread.name"] != null
assert tags["thread.id"] != null

// FIXME: DQH - Too much conditional logic? Maybe create specialized methods for client & server cases

boolean isRoot = (0G == spanParentId)
if (isRoot || distributedRootSpan) {
assert tags[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
} else {
assert tags[Config.RUNTIME_ID_TAG] == null
}

boolean isServer = (tags[Tags.SPAN_KIND] == Tags.SPAN_KIND_SERVER)
if (isRoot || distributedRootSpan || isServer) {
assert tags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
} else {
assert tags[Config.LANGUAGE_TAG_KEY] == null
}
}

def errorTags(Class<Throwable> errorType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.concurrent.Callable
class ConfigUtils {

static final CONFIG_INSTANCE_FIELD = Config.getDeclaredField("INSTANCE")
static final RUNTIME_ID_FIELD = Config.getDeclaredField("runtimeId")

@SneakyThrows
synchronized static <T extends Object> Object withConfigOverride(final String name, final String value, final Callable<T> r) {
Expand Down Expand Up @@ -52,16 +51,7 @@ class ConfigUtils {
assert Modifier.isVolatile(CONFIG_INSTANCE_FIELD.getModifiers())
assert !Modifier.isFinal(CONFIG_INSTANCE_FIELD.getModifiers())

assert Modifier.isPublic(RUNTIME_ID_FIELD.getModifiers())
assert !Modifier.isStatic(RUNTIME_ID_FIELD.getModifiers())
assert Modifier.isVolatile(RUNTIME_ID_FIELD.getModifiers())
assert !Modifier.isFinal(RUNTIME_ID_FIELD.getModifiers())

def previousConfig = CONFIG_INSTANCE_FIELD.get(null)
def newConfig = new Config()
CONFIG_INSTANCE_FIELD.set(null, newConfig)
if (previousConfig != null) {
RUNTIME_ID_FIELD.set(newConfig, RUNTIME_ID_FIELD.get(previousConfig))
}
}
}
83 changes: 0 additions & 83 deletions dd-trace-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.UUID;
import java.util.regex.Pattern;
import lombok.Getter;
import lombok.ToString;
Expand Down Expand Up @@ -43,9 +42,6 @@ public class Config {
public static final String INTEGRATIONS_ENABLED = "integrations.enabled";
public static final String WRITER_TYPE = "writer.type";
public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
public static final String GLOBAL_TAGS = "trace.global.tags";
public static final String SPAN_TAGS = "trace.span.tags";
public static final String JMX_TAGS = "trace.jmx.tags";
public static final String TRACE_ANNOTATIONS = "trace.annotations";
public static final String TRACE_EXECUTORS_ALL = "trace.executors.all";
public static final String TRACE_EXECUTORS = "trace.executors";
Expand All @@ -63,12 +59,6 @@ public class Config {

public static final String LOGS_INJECTION_ENABLED = "logs.injection";

public static final String SERVICE_TAG = "service";
@Deprecated public static final String SERVICE = SERVICE_TAG; // To be removed in 0.34.0
public static final String RUNTIME_ID_TAG = "runtime-id";
public static final String LANGUAGE_TAG_KEY = "language";
public static final String LANGUAGE_TAG_VALUE = "jvm";

public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";

private static final boolean DEFAULT_TRACE_ENABLED = true;
Expand Down Expand Up @@ -98,20 +88,11 @@ public class Config {
private static final String DEFAULT_TRACE_EXECUTORS = "";
private static final String DEFAULT_TRACE_METHODS = null;

/**
* this is a random UUID that gets generated on JVM start up and is attached to every root span
* and every JMX metric that is sent out.
*/
@Getter private final String runtimeId;

@Getter private final String serviceName;
@Getter private final boolean traceEnabled;
@Getter private final boolean integrationsEnabled;
@Getter private final String writerType;
@Getter private final boolean traceResolverEnabled;
private final Map<String, String> globalTags;
private final Map<String, String> spanTags;
private final Map<String, String> jmxTags;
@Getter private final List<String> excludedClasses;
@Getter private final Set<Integer> httpServerErrorStatuses;
@Getter private final Set<Integer> httpClientErrorStatuses;
Expand Down Expand Up @@ -139,8 +120,6 @@ public class Config {
Config() {
propertiesFromConfigFile = loadConfigurationFile();

runtimeId = UUID.randomUUID().toString();

serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME);

traceEnabled = getBooleanSettingFromEnvironment(TRACE_ENABLED, DEFAULT_TRACE_ENABLED);
Expand All @@ -150,10 +129,6 @@ public class Config {
traceResolverEnabled =
getBooleanSettingFromEnvironment(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);

globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null);
spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null);
jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null);

excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null);

httpServerErrorStatuses =
Expand Down Expand Up @@ -204,7 +179,6 @@ public class Config {

// Read order: Properties -> Parent
private Config(final Properties properties, final Config parent) {
runtimeId = parent.runtimeId;

serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName);

Expand All @@ -215,9 +189,6 @@ private Config(final Properties properties, final Config parent) {
traceResolverEnabled =
getPropertyBooleanValue(properties, TRACE_RESOLVER_ENABLED, parent.traceResolverEnabled);

globalTags = getPropertyMapValue(properties, GLOBAL_TAGS, parent.globalTags);
spanTags = getPropertyMapValue(properties, SPAN_TAGS, parent.spanTags);
jmxTags = getPropertyMapValue(properties, JMX_TAGS, parent.jmxTags);
excludedClasses =
getPropertyListValue(properties, TRACE_CLASSES_EXCLUDE, parent.excludedClasses);

Expand Down Expand Up @@ -266,53 +237,6 @@ private Config(final Properties properties, final Config parent) {
log.debug("New instance: {}", this);
}

/** @return A map of tags to be applied only to the local application root span. */
public Map<String, String> getLocalRootSpanTags() {
final Map<String, String> runtimeTags = getRuntimeTags();
final Map<String, String> result = new HashMap<>(runtimeTags);
result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);

return Collections.unmodifiableMap(result);
}

public Map<String, String> getMergedSpanTags() {
// DO not include runtimeId into span tags: we only want that added to the root span
final Map<String, String> result = newHashMap(globalTags.size() + spanTags.size());
result.putAll(globalTags);
result.putAll(spanTags);
return Collections.unmodifiableMap(result);
}

public Map<String, String> getMergedJmxTags() {
final Map<String, String> runtimeTags = getRuntimeTags();
final Map<String, String> result =
newHashMap(
globalTags.size() + jmxTags.size() + runtimeTags.size() + 1 /* for serviceName */);
result.putAll(globalTags);
result.putAll(jmxTags);
result.putAll(runtimeTags);
// service name set here instead of getRuntimeTags because apm already manages the service tag
// and may chose to override it.
// Additionally, infra/JMX metrics require `service` rather than APM's `service.name` tag
result.put(SERVICE_TAG, serviceName);
return Collections.unmodifiableMap(result);
}

/**
* Return a map of tags required by the datadog backend to link runtime metrics (i.e. jmx) and
* traces.
*
* <p>These tags must be applied to every runtime metrics and placed on the root span of every
* trace.
*
* @return A map of tag-name -> tag-value
*/
private Map<String, String> getRuntimeTags() {
final Map<String, String> result = newHashMap(2);
result.put(RUNTIME_ID_TAG, runtimeId);
return Collections.unmodifiableMap(result);
}

public boolean isIntegrationEnabled(
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
return integrationEnabled(integrationNames, defaultEnabled);
Expand Down Expand Up @@ -377,13 +301,6 @@ public static String getSettingFromEnvironment(final String name, final String d
return defaultValue;
}

/** @deprecated This method should only be used internally. Use the explicit getter instead. */
private static Map<String, String> getMapSettingFromEnvironment(
final String name, final String defaultValue) {
return parseMap(
getSettingFromEnvironment(name, defaultValue), propertyNameToSystemPropertyName(name));
}

/**
* Calls {@link #getSettingFromEnvironment(String, String)} and converts the result to a list by
* splitting on `,`.
Expand Down
Loading

0 comments on commit a4089ff

Please sign in to comment.