Introduce dd.tags
This commit is contained in:
parent
050298802a
commit
0752b07d92
|
@ -58,6 +58,8 @@ public class Config {
|
|||
public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
|
||||
public static final String SERVICE_MAPPING = "service.mapping";
|
||||
|
||||
public static final String TAGS = "tags";
|
||||
@Deprecated // Use dd.tags instead
|
||||
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";
|
||||
|
@ -211,7 +213,8 @@ public class Config {
|
|||
@Getter private final boolean prioritySamplingEnabled;
|
||||
@Getter private final boolean traceResolverEnabled;
|
||||
@Getter private final Map<String, String> serviceMapping;
|
||||
private final Map<String, String> globalTags;
|
||||
private final Map<String, String> tags;
|
||||
@Deprecated private final Map<String, String> globalTags;
|
||||
private final Map<String, String> spanTags;
|
||||
private final Map<String, String> jmxTags;
|
||||
@Getter private final List<String> excludedClasses;
|
||||
|
@ -303,6 +306,7 @@ public class Config {
|
|||
getBooleanSettingFromEnvironment(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);
|
||||
serviceMapping = getMapSettingFromEnvironment(SERVICE_MAPPING, null);
|
||||
|
||||
tags = getMapSettingFromEnvironment(TAGS, null);
|
||||
globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null);
|
||||
spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null);
|
||||
jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null);
|
||||
|
@ -485,6 +489,7 @@ public class Config {
|
|||
getPropertyBooleanValue(properties, TRACE_RESOLVER_ENABLED, parent.traceResolverEnabled);
|
||||
serviceMapping = getPropertyMapValue(properties, SERVICE_MAPPING, parent.serviceMapping);
|
||||
|
||||
tags = getPropertyMapValue(properties, TAGS, parent.tags);
|
||||
globalTags = getPropertyMapValue(properties, GLOBAL_TAGS, parent.globalTags);
|
||||
spanTags = getPropertyMapValue(properties, SPAN_TAGS, parent.spanTags);
|
||||
jmxTags = getPropertyMapValue(properties, JMX_TAGS, parent.jmxTags);
|
||||
|
@ -638,9 +643,9 @@ public class Config {
|
|||
}
|
||||
|
||||
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);
|
||||
// Do not include runtimeId into span tags: we only want that added to the root span
|
||||
final Map<String, String> result = newHashMap(getGlobalTags().size() + spanTags.size());
|
||||
result.putAll(getGlobalTags());
|
||||
result.putAll(spanTags);
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
@ -649,8 +654,8 @@ public class Config {
|
|||
final Map<String, String> runtimeTags = getRuntimeTags();
|
||||
final Map<String, String> result =
|
||||
newHashMap(
|
||||
globalTags.size() + jmxTags.size() + runtimeTags.size() + 1 /* for serviceName */);
|
||||
result.putAll(globalTags);
|
||||
getGlobalTags().size() + jmxTags.size() + runtimeTags.size() + 1 /* for serviceName */);
|
||||
result.putAll(getGlobalTags());
|
||||
result.putAll(jmxTags);
|
||||
result.putAll(runtimeTags);
|
||||
// service name set here instead of getRuntimeTags because apm already manages the service tag
|
||||
|
@ -665,12 +670,12 @@ public class Config {
|
|||
final String host = getHostName();
|
||||
final Map<String, String> result =
|
||||
newHashMap(
|
||||
globalTags.size()
|
||||
getGlobalTags().size()
|
||||
+ profilingTags.size()
|
||||
+ runtimeTags.size()
|
||||
+ 3 /* for serviceName and host and language */);
|
||||
result.put(HOST_TAG, host); // Host goes first to allow to override it
|
||||
result.putAll(globalTags);
|
||||
result.putAll(getGlobalTags());
|
||||
result.putAll(profilingTags);
|
||||
result.putAll(runtimeTags);
|
||||
// service name set here instead of getRuntimeTags because apm already manages the service tag
|
||||
|
@ -694,6 +699,14 @@ public class Config {
|
|||
return DEFAULT_ANALYTICS_SAMPLE_RATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide 'global' tags, i.e. tags set everywhere. We have to support old (dd.trace.global.tags)
|
||||
* version of this setting if new (dd.tags) version has not been specified.
|
||||
*/
|
||||
private Map<String, String> getGlobalTags() {
|
||||
return tags.isEmpty() ? globalTags : tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map of tags required by the datadog backend to link runtime metrics (i.e. jmx) and
|
||||
* traces.
|
||||
|
|
|
@ -56,6 +56,7 @@ import static datadog.trace.api.Config.SERVICE_NAME
|
|||
import static datadog.trace.api.Config.SERVICE_TAG
|
||||
import static datadog.trace.api.Config.SPAN_TAGS
|
||||
import static datadog.trace.api.Config.SPLIT_BY_TAGS
|
||||
import static datadog.trace.api.Config.TAGS
|
||||
import static datadog.trace.api.Config.TRACE_AGENT_PORT
|
||||
import static datadog.trace.api.Config.TRACE_ENABLED
|
||||
import static datadog.trace.api.Config.TRACE_RATE_LIMIT
|
||||
|
@ -76,8 +77,11 @@ class ConfigTest extends DDSpecification {
|
|||
private static final DD_TRACE_ENABLED_ENV = "DD_TRACE_ENABLED"
|
||||
private static final DD_WRITER_TYPE_ENV = "DD_WRITER_TYPE"
|
||||
private static final DD_SERVICE_MAPPING_ENV = "DD_SERVICE_MAPPING"
|
||||
private static final DD_SPAN_TAGS_ENV = "DD_SPAN_TAGS"
|
||||
private static final DD_HEADER_TAGS_ENV = "DD_HEADER_TAGS"
|
||||
private static final DD_TAGS_ENV = "DD_TAGS"
|
||||
private static final DD_GLOBAL_TAGS_ENV = "DD_TRACE_GLOBAL_TAGS"
|
||||
private static final DD_SPAN_TAGS_ENV = "DD_TRACE_SPAN_TAGS"
|
||||
private static final DD_HEADER_TAGS_ENV = "DD_TRACE_HEADER_TAGS"
|
||||
private static final DD_JMX_TAGS_ENV = "DD_TRACE_JMX_TAGS"
|
||||
private static final DD_PROPAGATION_STYLE_EXTRACT = "DD_PROPAGATION_STYLE_EXTRACT"
|
||||
private static final DD_PROPAGATION_STYLE_INJECT = "DD_PROPAGATION_STYLE_INJECT"
|
||||
private static final DD_JMXFETCH_METRICS_CONFIGS_ENV = "DD_JMXFETCH_METRICS_CONFIGS"
|
||||
|
@ -85,8 +89,9 @@ class ConfigTest extends DDSpecification {
|
|||
private static final DD_AGENT_PORT_LEGACY_ENV = "DD_AGENT_PORT"
|
||||
private static final DD_TRACE_REPORT_HOSTNAME = "DD_TRACE_REPORT_HOSTNAME"
|
||||
|
||||
private static final DD_PROFILING_API_KEY = "DD_PROFILING_API_KEY"
|
||||
private static final DD_PROFILING_API_KEY_OLD = "DD_PROFILING_APIKEY"
|
||||
private static final DD_PROFILING_API_KEY_ENV = "DD_PROFILING_API_KEY"
|
||||
private static final DD_PROFILING_API_KEY_OLD_ENV = "DD_PROFILING_APIKEY"
|
||||
private static final DD_PROFILING_TAGS_ENV = "DD_PROFILING_TAGS"
|
||||
|
||||
def "verify defaults"() {
|
||||
when:
|
||||
|
@ -379,7 +384,7 @@ class ConfigTest extends DDSpecification {
|
|||
environmentVariables.set(DD_PROPAGATION_STYLE_INJECT, "Datadog B3")
|
||||
environmentVariables.set(DD_JMXFETCH_METRICS_CONFIGS_ENV, "some/file")
|
||||
environmentVariables.set(DD_TRACE_REPORT_HOSTNAME, "true")
|
||||
environmentVariables.set(DD_PROFILING_API_KEY, "test-api-key")
|
||||
environmentVariables.set(DD_PROFILING_API_KEY_ENV, "test-api-key")
|
||||
|
||||
when:
|
||||
def config = new Config()
|
||||
|
@ -990,7 +995,7 @@ class ConfigTest extends DDSpecification {
|
|||
|
||||
def "verify api key loaded from file: #path"() {
|
||||
setup:
|
||||
environmentVariables.set(DD_PROFILING_API_KEY, "default-api-key")
|
||||
environmentVariables.set(DD_PROFILING_API_KEY_ENV, "default-api-key")
|
||||
System.setProperty(PREFIX + PROFILING_API_KEY_FILE, path)
|
||||
|
||||
when:
|
||||
|
@ -1007,7 +1012,7 @@ class ConfigTest extends DDSpecification {
|
|||
|
||||
def "verify api key loaded from file for old option name: #path"() {
|
||||
setup:
|
||||
environmentVariables.set(DD_PROFILING_API_KEY_OLD, "default-api-key")
|
||||
environmentVariables.set(DD_PROFILING_API_KEY_OLD_ENV, "default-api-key")
|
||||
System.setProperty(PREFIX + PROFILING_API_KEY_FILE_OLD, path)
|
||||
|
||||
when:
|
||||
|
@ -1033,4 +1038,65 @@ class ConfigTest extends DDSpecification {
|
|||
then:
|
||||
config.profilingApiKey == "test-api-key"
|
||||
}
|
||||
|
||||
def "verify dd.tags overrides global tags in properties"() {
|
||||
setup:
|
||||
def prop = new Properties()
|
||||
prop.setProperty(TAGS, "a:1")
|
||||
prop.setProperty(GLOBAL_TAGS, "b:2")
|
||||
prop.setProperty(SPAN_TAGS, "c:3")
|
||||
prop.setProperty(JMX_TAGS, "d:4")
|
||||
prop.setProperty(HEADER_TAGS, "e:5")
|
||||
prop.setProperty(PROFILING_TAGS, "f:6")
|
||||
|
||||
when:
|
||||
Config config = Config.get(prop)
|
||||
|
||||
then:
|
||||
config.mergedSpanTags == [a: "1", c: "3"]
|
||||
config.mergedJmxTags == [a: "1", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
|
||||
config.headerTags == [e: "5"]
|
||||
|
||||
config.mergedProfilingTags == [a: "1", f: "6", (HOST_TAG): config.getHostName(), (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
}
|
||||
|
||||
def "verify dd.tags overrides global tags in system properties"() {
|
||||
setup:
|
||||
System.setProperty(PREFIX + TAGS, "a:1")
|
||||
System.setProperty(PREFIX + GLOBAL_TAGS, "b:2")
|
||||
System.setProperty(PREFIX + SPAN_TAGS, "c:3")
|
||||
System.setProperty(PREFIX + JMX_TAGS, "d:4")
|
||||
System.setProperty(PREFIX + HEADER_TAGS, "e:5")
|
||||
System.setProperty(PREFIX + PROFILING_TAGS, "f:6")
|
||||
|
||||
when:
|
||||
Config config = new Config()
|
||||
|
||||
then:
|
||||
config.mergedSpanTags == [a: "1", c: "3"]
|
||||
config.mergedJmxTags == [a: "1", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
|
||||
config.headerTags == [e: "5"]
|
||||
|
||||
config.mergedProfilingTags == [a: "1", f: "6", (HOST_TAG): config.getHostName(), (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
}
|
||||
|
||||
def "verify dd.tags overrides global tags in env variables"() {
|
||||
setup:
|
||||
environmentVariables.set(DD_TAGS_ENV, "a:1")
|
||||
environmentVariables.set(DD_GLOBAL_TAGS_ENV, "b:2")
|
||||
environmentVariables.set(DD_SPAN_TAGS_ENV, "c:3")
|
||||
environmentVariables.set(DD_JMX_TAGS_ENV, "d:4")
|
||||
environmentVariables.set(DD_HEADER_TAGS_ENV, "e:5")
|
||||
environmentVariables.set(DD_PROFILING_TAGS_ENV, "f:6")
|
||||
|
||||
when:
|
||||
Config config = new Config()
|
||||
|
||||
then:
|
||||
config.mergedSpanTags == [a: "1", c: "3"]
|
||||
config.mergedJmxTags == [a: "1", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
|
||||
config.headerTags == [e: "5"]
|
||||
|
||||
config.mergedProfilingTags == [a: "1", f: "6", (HOST_TAG): config.getHostName(), (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue