Skip to content

Commit cb724ed

Browse files
committed
Fix tests and corner cases
1 parent 9392255 commit cb724ed

5 files changed

Lines changed: 13 additions & 9 deletions

File tree

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
6969
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
7070
import datadog.trace.bootstrap.instrumentation.api.TagContext;
71+
import datadog.trace.bootstrap.instrumentation.api.Tags;
7172
import datadog.trace.civisibility.interceptor.CiVisibilityApmProtocolInterceptor;
7273
import datadog.trace.civisibility.interceptor.CiVisibilityTelemetryInterceptor;
7374
import datadog.trace.civisibility.interceptor.CiVisibilityTraceInterceptor;
@@ -2074,6 +2075,9 @@ protected static final DDSpanContext buildSpanContext(
20742075
context.setAllTags(coreTags, coreTagsNeedsIntercept);
20752076
context.setAllTags(rootSpanTags, rootSpanTagsNeedsIntercept);
20762077
context.setAllTags(contextualTags);
2078+
// remove version here since will be done later on the postProcessor.
2079+
// it will allow knowing if it will be set manually or not
2080+
context.removeTag(Tags.VERSION);
20772081
return context;
20782082
}
20792083
}

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/InternalTagsAdder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class InternalTagsAdder extends TagsPostProcessor {
1616

1717
public InternalTagsAdder(@Nullable final String ddService, @Nullable final String version) {
1818
this.ddService = ddService != null ? UTF8BytesString.create(ddService) : null;
19-
this.version = version != null ? UTF8BytesString.create(version) : null;
19+
this.version = version != null && !version.isEmpty() ? UTF8BytesString.create(version) : null;
2020
}
2121

2222
@Override

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/TagsPostProcessorFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.List;
66

77
public final class TagsPostProcessorFactory {
8-
private static boolean addBaseService = true;
8+
private static boolean addInternalTags = true;
99
private static boolean addRemoteHostname = true;
1010

1111
private static class Lazy {
@@ -15,7 +15,7 @@ private static class Lazy {
1515
private static TagsPostProcessor createEagerChain() {
1616
final List<TagsPostProcessor> processors = new ArrayList<>(3);
1717
processors.add(new PeerServiceCalculator());
18-
if (addBaseService) {
18+
if (addInternalTags) {
1919
processors.add(
2020
new InternalTagsAdder(Config.get().getServiceName(), Config.get().getVersion()));
2121
}
@@ -67,8 +67,8 @@ public static TagsPostProcessor lazyProcessor() {
6767
*
6868
* @param enabled if false, {@link InternalTagsAdder} is not put in the chain.
6969
*/
70-
public static void withAddBaseService(boolean enabled) {
71-
addBaseService = enabled;
70+
public static void withAddInternalTags(boolean enabled) {
71+
addInternalTags = enabled;
7272
Lazy.eagerProcessor = Lazy.createEagerChain();
7373
}
7474

@@ -84,7 +84,7 @@ public static void withAddRemoteHostname(boolean enabled) {
8484

8585
/** Used for testing purposes. It reset the singleton and restore default options */
8686
public static void reset() {
87-
withAddBaseService(true);
87+
withAddInternalTags(true);
8888
withAddRemoteHostname(true);
8989
}
9090
}

dd-trace-core/src/test/groovy/datadog/trace/core/CoreTracerTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class CoreTracerTest extends DDCoreSpecification {
476476
setup:
477477
injectSysConfig(SERVICE_NAME, "dd_service_name")
478478
injectSysConfig(VERSION, "1.0.0")
479-
TagsPostProcessorFactory.withAddBaseService(true)
479+
TagsPostProcessorFactory.withAddInternalTags(true)
480480
def tracer = tracerBuilder().writer(new ListWriter()).build()
481481

482482
when:
@@ -491,7 +491,7 @@ class CoreTracerTest extends DDCoreSpecification {
491491
span2.finish()
492492
then:
493493
span2.getServiceName() == "dd_service_name"
494-
span2.getTags()["version"] == "1.0.0"
494+
span2.getTags()["version"]?.toString() == "1.0.0"
495495

496496
cleanup:
497497
tracer?.close()

dd-trace-core/src/test/groovy/datadog/trace/core/test/DDCoreSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class DDCoreSpecification extends DDSpecification {
4545

4646
@Override
4747
void setupSpec() {
48-
TagsPostProcessorFactory.withAddBaseService(false)
48+
TagsPostProcessorFactory.withAddInternalTags(false)
4949
TagsPostProcessorFactory.withAddRemoteHostname(false)
5050
}
5151

0 commit comments

Comments
 (0)