Skip to content

Commit af0a640

Browse files
committed
Move baggage tags unit test to HttpServerDecoratorTest
1 parent 5b52ea4 commit af0a640

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ public boolean accept(String key, String value) {
657657
}
658658
}
659659

660-
private static void setBaggageTags(TagContext tagContext, Map<String, String> baggage) {
660+
static void setBaggageTags(TagContext tagContext, Map<String, String> baggage) {
661661
List<String> baggageTagKeys = Config.get().getTraceBaggageTagKeys();
662662
if (baggageTagKeys.isEmpty()) {
663663
return;

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecoratorTest.groovy

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import datadog.trace.bootstrap.instrumentation.api.AgentTracer.TracerAPI
1717
import datadog.trace.bootstrap.instrumentation.api.ContextVisitors
1818
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities
1919
import datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities
20+
import datadog.trace.bootstrap.instrumentation.api.TagContext
2021
import datadog.trace.bootstrap.instrumentation.api.Tags
2122
import datadog.trace.bootstrap.instrumentation.api.URIDataAdapter
2223
import datadog.trace.bootstrap.instrumentation.api.URIDefaultDataAdapter
@@ -29,6 +30,7 @@ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_DE
2930
import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
3031
import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
3132
import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
33+
import static datadog.trace.api.config.TracerConfig.TRACE_BAGGAGE_TAG_KEYS
3234
import static datadog.trace.api.gateway.Events.EVENTS
3335

3436
class HttpServerDecoratorTest extends ServerDecoratorTest {
@@ -566,4 +568,54 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
566568
return reqHeaderDoneCount
567569
}
568570
}
571+
572+
def "test setBaggageTags default"() {
573+
setup:
574+
def tags = [:]
575+
576+
when:
577+
def tagContext = new TagContext()
578+
HttpServerDecorator.setBaggageTags(tagContext, ["user.id": "doggo", "account.id": "test", "session.id": "1234", "region": "us -east - 1"])
579+
tagContext.tags.fillMap(tags)
580+
581+
then:
582+
tags == ["baggage.user.id": "doggo", "baggage.account.id": "test", "baggage.session.id": "1234"]
583+
}
584+
585+
def "test setBaggageTags does not overwrite"() {
586+
setup:
587+
def tags = [:]
588+
589+
when:
590+
def tagContext = new TagContext()
591+
tagContext.putTag("baggage.account.id", "staging")
592+
HttpServerDecorator.setBaggageTags(tagContext, ["user.id": "doggo", "account.id": "test", "session.id": "1234", "region": "us -east - 1"])
593+
tagContext.tags.fillMap(tags)
594+
595+
then:
596+
tags == ["baggage.user.id": "doggo", "baggage.account.id": "staging", "baggage.session.id": "1234"]
597+
}
598+
599+
def "test setBaggageTags with different configurations"() {
600+
setup:
601+
injectSysConfig(TRACE_BAGGAGE_TAG_KEYS, baggageTagKeysConfig)
602+
def tags = [:]
603+
604+
when:
605+
def tagContext = new TagContext()
606+
HttpServerDecorator.setBaggageTags(tagContext, ["user.id": "doggo", "foo": "bar", "language": "en"])
607+
tagContext.tags.fillMap(tags)
608+
609+
then:
610+
tags == expectedTags
611+
612+
where:
613+
baggageTagKeysConfig | expectedTags
614+
"*" | ["baggage.user.id": "doggo", "baggage.foo": "bar", "baggage.language": "en"]
615+
" " | [:]
616+
"system.id" | [:]
617+
"user.id" | ["baggage.user.id": "doggo"]
618+
"foo" | ["baggage.foo": "bar"]
619+
"user.id,foo" | ["baggage.user.id": "doggo", "baggage.foo": "bar"]
620+
}
569621
}

0 commit comments

Comments
 (0)