Skip to content

Commit 86896d7

Browse files
dougqhclaude
andcommitted
Add tests for snapshotted trace-stats additional tags
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f5b083b commit 86896d7

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package datadog.trace.api;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import java.util.Properties;
7+
import java.util.Set;
8+
import org.junit.jupiter.api.Test;
9+
10+
class TraceStatsAdditionalTagsTest {
11+
12+
private static Config configWith(String experimentalFeatures, String additionalTags) {
13+
Properties props = new Properties();
14+
if (experimentalFeatures != null) {
15+
props.setProperty("trace.experimental.features.enabled", experimentalFeatures);
16+
}
17+
if (additionalTags != null) {
18+
props.setProperty("trace.stats.additional.tags", additionalTags);
19+
}
20+
return Config.get(props);
21+
}
22+
23+
@Test
24+
void returnsConfiguredTagsWhenFeatureEnabled() {
25+
Config config = configWith("DD_TRACE_STATS_ADDITIONAL_TAGS", "peer.hostname,messaging.system");
26+
Set<String> tags = config.getTraceStatsAdditionalTags();
27+
assertEquals(2, tags.size());
28+
assertTrue(tags.contains("peer.hostname"));
29+
assertTrue(tags.contains("messaging.system"));
30+
}
31+
32+
@Test
33+
void emptyWhenFeatureNotEnabled() {
34+
// The value is configured but the experimental feature gate is closed.
35+
Config config = configWith(null, "peer.hostname");
36+
assertTrue(config.getTraceStatsAdditionalTags().isEmpty());
37+
}
38+
39+
@Test
40+
void returnsSameSnapshotInstanceOnEachCall() {
41+
// The setting is snapshotted into a final field at construction, so repeated reads
42+
// return the identical immutable instance rather than re-querying the config source.
43+
Config config = configWith("DD_TRACE_STATS_ADDITIONAL_TAGS", "peer.hostname");
44+
assertEquals(config.getTraceStatsAdditionalTags(), config.getTraceStatsAdditionalTags());
45+
}
46+
47+
@Test
48+
void includedInToString() {
49+
Config config = configWith("DD_TRACE_STATS_ADDITIONAL_TAGS", "peer.hostname");
50+
assertTrue(config.toString().contains("traceStatsAdditionalTags="));
51+
}
52+
}

0 commit comments

Comments
 (0)