Skip to content

Commit 437383f

Browse files
Apply PR feedback (2)
1 parent 13dfddb commit 437383f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public static void install() {
6565
if (isEmpty(endpoint)) {
6666
endpoint = String.format("https://app.%s/api/v2/ai-guard", config.getSite());
6767
}
68-
final Map<String, String> headers = new HashMap<>(2);
69-
headers.put("DD-API-KEY", apiKey);
70-
headers.put("DD-APP-KEY", appKey);
68+
final Map<String, String> headers = mapOf("DD-API-KEY", apiKey, "DD-APP-KEY", appKey);
7169
final HttpUrl url = HttpUrl.get(endpoint).newBuilder().addPathSegment("evaluate").build();
7270
final int timeout = config.getAiGuardTimeout();
7371
final OkHttpClient client = buildClient(url, timeout);
@@ -91,9 +89,7 @@ static void uninstall() {
9189
this.client = client;
9290
this.moshi = new Moshi.Builder().build();
9391
final Config config = Config.get();
94-
this.meta = new HashMap<>(2);
95-
this.meta.put("service", config.getServiceName());
96-
this.meta.put("env", config.getEnv());
92+
this.meta = mapOf("service", config.getServiceName(), "env", config.getEnv());
9793
}
9894

9995
private static List<Message> truncate(List<Message> messages) {
@@ -233,6 +229,14 @@ private static boolean isEmpty(final String value) {
233229
return value == null || value.isEmpty();
234230
}
235231

232+
private static Map<String, String> mapOf(
233+
final String key1, final String prop1, final String key2, final String prop2) {
234+
final Map<String, String> map = new HashMap<>(2);
235+
map.put(key1, prop1);
236+
map.put(key2, prop2);
237+
return map;
238+
}
239+
236240
private static class Installer extends AIGuard {
237241
public static void install(final Evaluator evaluator) {
238242
AIGuard.EVALUATOR = evaluator;

0 commit comments

Comments
 (0)