Skip to content

Commit 9f5d390

Browse files
committed
Populate the base hash with the container tag hash if the process tag propagation feature flag is enabled
1 parent 6c07df1 commit 9f5d390

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultPathwayContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.datadoghq.sketch.ddsketch.encoding.ByteArrayInput;
88
import com.datadoghq.sketch.ddsketch.encoding.GrowingByteArrayOutput;
99
import com.datadoghq.sketch.ddsketch.encoding.VarEncodingHelper;
10+
import datadog.common.container.ContainerInfo;
1011
import datadog.context.propagation.CarrierVisitor;
1112
import datadog.trace.api.Config;
1213
import datadog.trace.api.ProcessTags;
@@ -280,6 +281,10 @@ public static long getBaseHash(WellKnownTags wellKnownTags) {
280281
CharSequence processTags = ProcessTags.getTagsForSerialization();
281282
if (processTags != null) {
282283
builder.append(processTags);
284+
String containerTagsHash = ContainerInfo.get().getContainerTagsHash();
285+
if (containerTagsHash != null && !containerTagsHash.isEmpty()) {
286+
builder.append(containerTagsHash);
287+
}
283288
}
284289
return FNV64Hash.generateHash(builder.toString(), FNV64Hash.Version.v1);
285290
}

dd-trace-core/src/test/groovy/datadog/trace/core/datastreams/DefaultPathwayContextTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.core.datastreams
22

3+
import datadog.common.container.ContainerInfo
34
import datadog.communication.ddagent.DDAgentFeaturesDiscovery
45
import datadog.trace.api.Config
56
import datadog.trace.api.DDTraceId
@@ -481,6 +482,32 @@ class DefaultPathwayContextTest extends DDCoreSpecification {
481482
ProcessTags.reset()
482483
}
483484
485+
def "ContainerTagsHash used in hash calculation when enabled propagateTagsEnabled=#propagateTagsEnabled"() {
486+
when:
487+
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, propagateTagsEnabled.toString())
488+
ProcessTags.reset()
489+
ProcessTags.addTag("000", "first")
490+
def firstBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags)
491+
492+
then:
493+
ContainerInfo.get().setContainerTagsHash("<test-container-tags-hash>")
494+
def secondBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags)
495+
496+
expect:
497+
if (propagateTagsEnabled) {
498+
assert secondBaseHash != firstBaseHash
499+
} else {
500+
assert secondBaseHash == firstBaseHash
501+
}
502+
503+
cleanup:
504+
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false")
505+
ProcessTags.reset()
506+
507+
where:
508+
propagateTagsEnabled << [true, false]
509+
}
510+
484511
def "Check context extractor decorator behavior"() {
485512
given:
486513
def sink = Mock(Sink)

0 commit comments

Comments
 (0)