@@ -17,6 +17,7 @@ import datadog.trace.bootstrap.instrumentation.api.AgentTracer.TracerAPI
1717import datadog.trace.bootstrap.instrumentation.api.ContextVisitors
1818import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities
1919import datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities
20+ import datadog.trace.bootstrap.instrumentation.api.TagContext
2021import datadog.trace.bootstrap.instrumentation.api.Tags
2122import datadog.trace.bootstrap.instrumentation.api.URIDataAdapter
2223import datadog.trace.bootstrap.instrumentation.api.URIDefaultDataAdapter
@@ -29,6 +30,7 @@ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_DE
2930import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
3031import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
3132import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
33+ import static datadog.trace.api.config.TracerConfig.TRACE_BAGGAGE_TAG_KEYS
3234import static datadog.trace.api.gateway.Events.EVENTS
3335
3436class 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