Skip to content

Commit 35add1e

Browse files
committed
check for empty env when setting cloud payload tagging
1 parent 9fb4984 commit 35add1e

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,10 +2760,21 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
27602760
this.cloudPayloadTaggingServices =
27612761
configProvider.getSet(
27622762
TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES, DEFAULT_TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES);
2763-
this.cloudRequestPayloadTagging =
2763+
2764+
List<String> cloudReqPayloadTaggingConf =
27642765
configProvider.getList(TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, null);
2765-
this.cloudResponsePayloadTagging =
2766+
this.cloudRequestPayloadTagging =
2767+
cloudReqPayloadTaggingConf != null && cloudReqPayloadTaggingConf.isEmpty()
2768+
? null
2769+
: cloudReqPayloadTaggingConf;
2770+
2771+
List<String> cloudRespPayloadTaggingConf =
27662772
configProvider.getList(TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, null);
2773+
this.cloudResponsePayloadTagging =
2774+
cloudRespPayloadTaggingConf != null && cloudRespPayloadTaggingConf.isEmpty()
2775+
? null
2776+
: cloudRespPayloadTaggingConf;
2777+
27672778
this.cloudPayloadTaggingMaxDepth =
27682779
configProvider.getInteger(TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH, 10);
27692780
this.cloudPayloadTaggingMaxTags =

internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLING_OPERATION_RUL
137137
import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLING_SERVICE_RULES
138138
import static datadog.trace.api.config.TracerConfig.TRACE_X_DATADOG_TAGS_MAX_LENGTH
139139
import static datadog.trace.api.config.TracerConfig.WRITER_TYPE
140+
import static datadog.trace.api.config.TracerConfig.TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING
141+
import static datadog.trace.api.config.TracerConfig.TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING
140142
import datadog.trace.config.inversion.ConfigHelper
141143

142144
class ConfigTest extends DDSpecification {
@@ -173,6 +175,8 @@ class ConfigTest extends DDSpecification {
173175
private static final DD_LLMOBS_ENABLED_ENV = "DD_LLMOBS_ENABLED"
174176
private static final DD_LLMOBS_ML_APP_ENV = "DD_LLMOBS_ML_APP"
175177
private static final DD_LLMOBS_AGENTLESS_ENABLED_ENV = "DD_LLMOBS_AGENTLESS_ENABLED"
178+
private static final DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING_ENV = "DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING"
179+
private static final DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING_ENV = "DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING"
176180

177181
def setup() {
178182
FixedCapturedEnvironment.useFixedEnv([:])
@@ -271,6 +275,9 @@ class ConfigTest extends DDSpecification {
271275
prop.setProperty(TRACE_X_DATADOG_TAGS_MAX_LENGTH, "128")
272276
prop.setProperty(JDK_SOCKET_ENABLED, "false")
273277

278+
prop.setProperty(TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, "all")
279+
prop.setProperty(TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, "all")
280+
274281
when:
275282
Config config = Config.get(prop)
276283

@@ -366,6 +373,8 @@ class ConfigTest extends DDSpecification {
366373
config.debuggerExceptionEnabled == true
367374
config.jdkSocketEnabled == false
368375

376+
config.cloudRequestPayloadTagging == ["all"]
377+
config.cloudResponsePayloadTagging == ["all"]
369378
config.xDatadogTagsMaxLength == 128
370379
}
371380

@@ -460,6 +469,9 @@ class ConfigTest extends DDSpecification {
460469
System.setProperty(PREFIX + DYNAMIC_INSTRUMENTATION_EXCLUDE_FILES, "exclude file")
461470
System.setProperty(PREFIX + TRACE_X_DATADOG_TAGS_MAX_LENGTH, "128")
462471

472+
System.setProperty(PREFIX + TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, "all")
473+
System.setProperty(PREFIX + TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, "all")
474+
463475
when:
464476
Config config = new Config()
465477

@@ -551,6 +563,9 @@ class ConfigTest extends DDSpecification {
551563
config.dynamicInstrumentationInstrumentTheWorld == "method"
552564
config.dynamicInstrumentationExcludeFiles == "exclude file"
553565

566+
config.cloudRequestPayloadTagging == ["all"]
567+
config.cloudResponsePayloadTagging == ["all"]
568+
554569
config.xDatadogTagsMaxLength == 128
555570
}
556571

@@ -570,6 +585,8 @@ class ConfigTest extends DDSpecification {
570585
environmentVariables.set(DD_TRACE_LONG_RUNNING_ENABLED, "true")
571586
environmentVariables.set(DD_TRACE_LONG_RUNNING_FLUSH_INTERVAL, "81")
572587
environmentVariables.set(DD_TRACE_HEADER_TAGS, "*")
588+
environmentVariables.set(DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING_ENV, "all")
589+
environmentVariables.set(DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING_ENV, "all")
573590

574591
when:
575592
def config = new Config()
@@ -591,6 +608,8 @@ class ConfigTest extends DDSpecification {
591608
config.getLongRunningTraceFlushInterval() == 81
592609
config.requestHeaderTags == ["*":"http.request.headers."]
593610
config.responseHeaderTags == ["*":"http.response.headers."]
611+
config.cloudRequestPayloadTagging == ["all"]
612+
config.cloudResponsePayloadTagging == ["all"]
594613
}
595614

596615
def "sys props override env vars"() {
@@ -600,13 +619,17 @@ class ConfigTest extends DDSpecification {
600619
environmentVariables.set(DD_PRIORITIZATION_TYPE_ENV, "EnsureTrace")
601620
environmentVariables.set(DD_TRACE_AGENT_PORT_ENV, "777")
602621
environmentVariables.set(DD_TRACE_LONG_RUNNING_ENABLED, "false")
622+
environmentVariables.set(DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING_ENV, "all")
623+
environmentVariables.set(DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING_ENV, "all")
603624

604625
System.setProperty(PREFIX + SERVICE_NAME, "what we actually want")
605626
System.setProperty(PREFIX + WRITER_TYPE, "DDAgentWriter")
606627
System.setProperty(PREFIX + PRIORITIZATION_TYPE, "FastLane")
607628
System.setProperty(PREFIX + AGENT_HOST, "somewhere")
608629
System.setProperty(PREFIX + TRACE_AGENT_PORT, "123")
609630
System.setProperty(PREFIX + TRACE_LONG_RUNNING_ENABLED, "true")
631+
System.setProperty(PREFIX + TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, "\$.path1,\$.path2")
632+
System.setProperty(PREFIX + TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, "\$.path3,\$.path4")
610633

611634
when:
612635
def config = new Config()
@@ -619,6 +642,8 @@ class ConfigTest extends DDSpecification {
619642
config.agentUrl == "http://somewhere:123"
620643
config.longRunningTraceEnabled
621644
config.longRunningTraceFlushInterval == 120
645+
config.cloudRequestPayloadTagging == ["\$.path1", "\$.path2"]
646+
config.cloudResponsePayloadTagging == ["\$.path3", "\$.path4"]
622647
}
623648

624649
def "default when configured incorrectly"() {
@@ -2596,6 +2621,25 @@ class ConfigTest extends DDSpecification {
25962621
ConfigHelper.get().setConfigInversionStrict(strictness)
25972622
}
25982623

2624+
def "set cloud payload tagging to null if invalid or empty value is passed as env"() {
2625+
setup:
2626+
environmentVariables.set(DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING_ENV, "")
2627+
environmentVariables.set(DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING_ENV, "")
2628+
2629+
when:
2630+
def config = new Config()
2631+
2632+
then:
2633+
config.cloudRequestPayloadTagging == []
2634+
config.@cloudRequestPayloadTagging == null
2635+
2636+
config.cloudResponsePayloadTagging == []
2637+
config.@cloudResponsePayloadTagging == null
2638+
2639+
!config.isCloudRequestPayloadTaggingEnabled()
2640+
!config.isCloudResponsePayloadTaggingEnabled()
2641+
}
2642+
25992643
def "verify rule config #name"() {
26002644
setup:
26012645
environmentVariables.set("DD_TRACE_TEST_ENABLED", "true")

0 commit comments

Comments
 (0)