Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: logging not 200 responses #199

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/com/epam/aidial/core/ProxyContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

@Slf4j
@Getter
@Setter
public class ProxyContext {

private static final int LOG_MAX_ERROR_LENGTH = 200;

private final Config config;
// API key of root requester
private final Key key;
Expand Down Expand Up @@ -106,8 +110,16 @@ public Future<Void> respond(HttpStatus status, Object object) {
}

public Future<Void> respond(HttpStatus status, String body) {
return response.setStatusCode(status.getCode())
.end(body == null ? "" : body);
if (body == null) {
body = "";
}

if (status != HttpStatus.OK) {
log.warn("Responding with error. Trace: {}. Span: {}. Status: {}. Body: {}", traceId, spanId, status,
body.length() > LOG_MAX_ERROR_LENGTH ? body.substring(0, LOG_MAX_ERROR_LENGTH) : body);
}

return response.setStatusCode(status.getCode()).end(body);
}

public String getProject() {
Expand Down
Loading