44import static datadog .trace .api .telemetry .WafMetricCollector .AIGuardTruncationType .CONTENT ;
55import static datadog .trace .api .telemetry .WafMetricCollector .AIGuardTruncationType .MESSAGES ;
66import static datadog .trace .util .Strings .isBlank ;
7- import static java .util .Collections .singletonMap ;
87
98import com .squareup .moshi .JsonAdapter ;
109import com .squareup .moshi .JsonReader ;
@@ -69,7 +68,8 @@ public BadConfigurationException(final String message) {
6968 static final String REASON_TAG = "ai_guard.reason" ;
7069 static final String BLOCKED_TAG = "ai_guard.blocked" ;
7170 static final String META_STRUCT_TAG = "ai_guard" ;
72- static final String META_STRUCT_KEY = "messages" ;
71+ static final String META_STRUCT_MESSAGES = "messages" ;
72+ static final String META_STRUCT_MATCHING_RULES = "matching_rules" ;
7373
7474 public static void install () {
7575 final Config config = Config .get ();
@@ -208,8 +208,8 @@ public Evaluation evaluate(final List<Message> messages, final Options options)
208208 } else {
209209 span .setTag (TARGET_TAG , "prompt" );
210210 }
211- final Map <String , Object > metaStruct =
212- singletonMap ( META_STRUCT_KEY , messagesForMetaStruct (messages ));
211+ final Map <String , Object > metaStruct = new HashMap <>( 2 );
212+ metaStruct . put ( META_STRUCT_MESSAGES , messagesForMetaStruct (messages ));
213213 span .setMetaStruct (META_STRUCT_TAG , metaStruct );
214214 final Request .Builder request =
215215 new Request .Builder ()
@@ -230,10 +230,8 @@ public Evaluation evaluate(final List<Message> messages, final Options options)
230230 if (reason != null ) {
231231 span .setTag (REASON_TAG , reason );
232232 }
233- if (tags != null ) {
234- for (final String tag : tags ) {
235- span .setTag ("ai_guard.tags." + tag , true );
236- }
233+ if (tags != null && !tags .isEmpty ()) {
234+ metaStruct .put (META_STRUCT_MATCHING_RULES , tags );
237235 }
238236 final boolean shouldBlock =
239237 isBlockingEnabled (options , result .get ("is_blocking_enabled" )) && action != Action .ALLOW ;
0 commit comments