673673import static datadog .trace .util .CollectionUtils .tryMakeImmutableList ;
674674import static datadog .trace .util .CollectionUtils .tryMakeImmutableSet ;
675675import static datadog .trace .util .ConfigStrings .propertyNameToEnvironmentVariableName ;
676+ import static datadog .trace .util .json .JsonPathParser .parseJsonPaths ;
676677
677678import datadog .environment .JavaVirtualMachine ;
678679import datadog .environment .OperatingSystem ;
704705import datadog .trace .util .PidHelper ;
705706import datadog .trace .util .RandomUtils ;
706707import datadog .trace .util .Strings ;
708+ import datadog .trace .util .json .JsonPath ;
707709import datadog .trace .util .throwable .FatalAgentMisconfigurationError ;
708710import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
709711import java .io .BufferedReader ;
@@ -1283,8 +1285,8 @@ public static String getHostName() {
12831285 private final String agentlessLogSubmissionProduct ;
12841286
12851287 private final Set <String > cloudPayloadTaggingServices ;
1286- @ Nullable private final List <String > cloudRequestPayloadTagging ;
1287- @ Nullable private final List <String > cloudResponsePayloadTagging ;
1288+ @ Nullable private final List <JsonPath > cloudRequestPayloadTagging ;
1289+ @ Nullable private final List <JsonPath > cloudResponsePayloadTagging ;
12881290 private final int cloudPayloadTaggingMaxDepth ;
12891291 private final int cloudPayloadTaggingMaxTags ;
12901292
@@ -2861,10 +2863,39 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
28612863 this .cloudPayloadTaggingServices =
28622864 configProvider .getSet (
28632865 TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES , DEFAULT_TRACE_CLOUD_PAYLOAD_TAGGING_SERVICES );
2864- this .cloudRequestPayloadTagging =
2866+
2867+ List <String > cloudReqPayloadTaggingConf =
28652868 configProvider .getList (TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING , null );
2866- this .cloudResponsePayloadTagging =
2869+ if (null == cloudReqPayloadTaggingConf ) {
2870+ // if no configuration is provided, disable payload tagging
2871+ this .cloudRequestPayloadTagging = null ;
2872+ } else if (cloudReqPayloadTaggingConf .size () == 1
2873+ && cloudReqPayloadTaggingConf .get (0 ).equalsIgnoreCase ("all" )) {
2874+ // if "all" is specified enable all JSON paths
2875+ this .cloudRequestPayloadTagging = Collections .emptyList ();
2876+ } else {
2877+ // parse and validate JSON paths. if none are valid, disable payload tagging
2878+ List <JsonPath > validRequestJsonPaths = parseJsonPaths (cloudReqPayloadTaggingConf );
2879+ this .cloudRequestPayloadTagging =
2880+ validRequestJsonPaths .isEmpty () ? null : validRequestJsonPaths ;
2881+ }
2882+
2883+ List <String > cloudRespPayloadTaggingConf =
28672884 configProvider .getList (TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING , null );
2885+ if (null == cloudRespPayloadTaggingConf ) {
2886+ // if no configuration is provided, disable payload tagging
2887+ this .cloudResponsePayloadTagging = null ;
2888+ } else if (cloudRespPayloadTaggingConf .size () == 1
2889+ && cloudRespPayloadTaggingConf .get (0 ).equalsIgnoreCase ("all" )) {
2890+ // if "all" is specified enable all JSON paths
2891+ this .cloudResponsePayloadTagging = Collections .emptyList ();
2892+ } else {
2893+ // parse and validate JSON paths. if none are valid, disable payload tagging
2894+ List <JsonPath > validResponseJsonPaths = parseJsonPaths (cloudRespPayloadTaggingConf );
2895+ this .cloudResponsePayloadTagging =
2896+ validResponseJsonPaths .isEmpty () ? null : validResponseJsonPaths ;
2897+ }
2898+
28682899 this .cloudPayloadTaggingMaxDepth =
28692900 configProvider .getInteger (TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH , 10 );
28702901 this .cloudPayloadTaggingMaxTags =
@@ -5315,7 +5346,7 @@ public boolean isCloudPayloadTaggingEnabled() {
53155346 return isCloudRequestPayloadTaggingEnabled () || isCloudResponsePayloadTaggingEnabled ();
53165347 }
53175348
5318- public List <String > getCloudRequestPayloadTagging () {
5349+ public List <JsonPath > getCloudRequestPayloadTagging () {
53195350 return cloudRequestPayloadTagging == null
53205351 ? Collections .emptyList ()
53215352 : cloudRequestPayloadTagging ;
@@ -5325,7 +5356,7 @@ public boolean isCloudRequestPayloadTaggingEnabled() {
53255356 return cloudRequestPayloadTagging != null ;
53265357 }
53275358
5328- public List <String > getCloudResponsePayloadTagging () {
5359+ public List <JsonPath > getCloudResponsePayloadTagging () {
53295360 return cloudResponsePayloadTagging == null
53305361 ? Collections .emptyList ()
53315362 : cloudResponsePayloadTagging ;
0 commit comments