Skip to content

Commit 3c243ef

Browse files
Fix coverage and add tags to exception
1 parent c8c8e6e commit 3c243ef

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

dd-java-agent/agent-aiguard/src/main/java/com/datadog/aiguard/AIGuardInternal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public Evaluation evaluate(final List<Message> messages, final Options options)
238238
WafMetricCollector.get().aiGuardRequest(action, shouldBlock);
239239
if (shouldBlock) {
240240
span.setTag(BLOCKED_TAG, true);
241-
throw new AIGuardAbortError(action, reason);
241+
throw new AIGuardAbortError(action, reason, tags);
242242
}
243243
return new Evaluation(action, reason);
244244
}

dd-java-agent/agent-aiguard/src/test/groovy/com/datadog/aiguard/AIGuardInternalTests.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ class AIGuardInternalTests extends DDSpecification {
452452
0 * span.setTag(AIGuardInternal.TOOL_TAG, _)
453453
}
454454

455+
void 'map requires even number of params'() {
456+
when:
457+
AIGuardInternal.mapOf('1', '2', '3')
458+
459+
then:
460+
thrown(IllegalArgumentException)
461+
}
462+
455463
private static assertTelemetry(final String metric, final String...tags) {
456464
final metrics = WafMetricCollector.get().with {
457465
prepareMetrics()

dd-trace-api/src/main/java/datadog/trace/api/aiguard/AIGuard.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ public static Evaluation evaluate(final List<Message> messages, final Options op
6363
public static class AIGuardAbortError extends RuntimeException {
6464
private final Action action;
6565
private final String reason;
66+
private final List<String> tags;
6667

67-
public AIGuardAbortError(final Action action, final String reason) {
68+
public AIGuardAbortError(final Action action, final String reason, final List<String> tags) {
6869
super(reason);
6970
this.action = action;
7071
this.reason = reason;
72+
this.tags = tags;
7173
}
7274

7375
public Action getAction() {
@@ -77,6 +79,10 @@ public Action getAction() {
7779
public String getReason() {
7880
return reason;
7981
}
82+
83+
public List<String> getTags() {
84+
return tags;
85+
}
8086
}
8187

8288
/**

0 commit comments

Comments
 (0)