Skip to content

Commit 00142be

Browse files
authored
fix: [Core] Remove any logging of response request body (#504)
* Remove logging response/request - error messages updated and cut error object logging * minor * update release notes --------- Co-authored-by: Roshin Rajan Panackal <[email protected]>
1 parent 3a3d275 commit 00142be

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ private T parseResponse(@Nonnull final ClassicHttpResponse response) throws E {
7878
throw exceptionConstructor.apply("Response was empty.", null);
7979
}
8080
val content = getContent(responseEntity);
81-
log.debug("Parsing response from JSON response: {}", content);
8281
try {
8382
return objectMapper.readValue(content, responseType);
8483
} catch (final JsonProcessingException e) {
85-
log.error("Failed to parse the following response: {}", content);
84+
log.error("Failed to parse response to type {}", responseType);
8685
throw exceptionConstructor.apply("Failed to parse response", e);
8786
}
8887
}
@@ -92,7 +91,7 @@ private String getContent(@Nonnull final HttpEntity entity) {
9291
try {
9392
return EntityUtils.toString(entity, StandardCharsets.UTF_8);
9493
} catch (IOException | ParseException e) {
95-
throw exceptionConstructor.apply("Failed to read response content.", e);
94+
throw exceptionConstructor.apply("Failed to read response content", e);
9695
}
9796
}
9897

@@ -122,7 +121,10 @@ public void buildExceptionAndThrow(@Nonnull final ClassicHttpResponse response)
122121
throw exception;
123122
}
124123

125-
log.error("The service responded with an HTTP error and the following content: {}", content);
124+
log.error(
125+
"The service responded with an HTTP {} ({})",
126+
response.getCode(),
127+
response.getReasonPhrase());
126128
val contentType = ContentType.parse(entity.getContentType());
127129
if (!ContentType.APPLICATION_JSON.isSameMimeType(contentType)) {
128130
throw exception;

core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public Stream<D> handleStreamingResponse(@Nonnull final ClassicHttpResponse resp
7777
try {
7878
return objectMapper.readValue(data, responseType);
7979
} catch (final IOException e) { // exception message e gets lost
80-
log.error("Failed to parse the following response: {}", line);
81-
throw exceptionConstructor.apply("Failed to parse delta message: " + line, e);
80+
log.error("Failed to parse delta chunk to type {}", responseType);
81+
throw exceptionConstructor.apply("Failed to parse delta chunk", e);
8282
}
8383
});
8484
}

core/src/main/java/com/sap/ai/sdk/core/common/IterableStreamConverter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean hasNext() {
7070
} catch (final Exception e) {
7171
isDone = true;
7272
stopHandler.run();
73-
log.debug("Error while reading next element.", e);
73+
log.debug("Reading next element failed with error {})", e.getClass().getSimpleName());
7474
throw errorHandler.apply(e);
7575
}
7676
return !isDone;
@@ -114,7 +114,13 @@ static Stream<String> lines(
114114

115115
final var reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8), BUFFER_SIZE);
116116
final Runnable closeHandler =
117-
() -> Try.run(reader::close).onFailure(e -> log.error("Could not close input stream", e));
117+
() ->
118+
Try.run(reader::close)
119+
.onFailure(
120+
e ->
121+
log.debug(
122+
"Could not close input stream with error: {} (ignored)",
123+
e.getClass().getSimpleName()));
118124
final Function<Exception, RuntimeException> errHandler =
119125
e -> exceptionType.apply("Parsing response content was interrupted.", e);
120126

docs/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@
5050
### 🐛 Fixed Issues
5151

5252
- [Orchestration] Resolved duplicate JSON property issue, enabling Anthropic Claude chat completions.
53+
- Remove logging of any request/response payloads to avoid potential exposure of sensitive data.

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <T> T execute(
4040
@Nonnull final Class<T> responseType) {
4141
try {
4242
val json = JACKSON.writeValueAsString(payload);
43-
log.debug("Serialized request into JSON payload: {}", json);
43+
log.debug("Successfully serialized request into JSON payload");
4444
val request = new HttpPost(path);
4545
request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
4646

0 commit comments

Comments
 (0)