Since https://github.com/elastic/elasticsearch/pull/55774 we log exceptions reaching the RestResponse class on their way back to the client in the "rest.suppressed" logger. Status codes <500 are logged on the Debug and >=500 codes are logged on the Warn level.
However there is some logic that doesn't log these errors if the user has requested "error_trace" in the request parameters.
In this case we don't log. To improve visibility of 500s on the server side logs and to be able to measure and alert on occasions of this status code we should remove this condition and always log 500s (and probably 400s on Debug like already done today).
server/src/main/java/org/elasticsearch/rest/RestResponse.java
import java.util.Objects;
import java.util.Set;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE;
import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT;
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.elasticsearch.rest.RestController.ELASTIC_PRODUCT_HTTP_HEADER;
public class RestResponse {
    public static final String TEXT_CONTENT_TYPE = "text/plain; charset=UTF-8";
    private static final String STATUS = "status";
    private static final Logger SUPPRESSED_ERROR_LOGGER = LogManager.getLogger("rest.suppressed");
    private final RestStatus status;
    @Nullable
    private final BytesReference content;
    @Nullable
    private final ChunkedRestResponseBody chunkedResponseBody;
    private final String responseMediaType;
    private Map<String, List<String>> customHeaders;
    /**
     * Creates a new response based on {@link XContentBuilder}.
     */
    public RestResponse(RestStatus status, XContentBuilder builder) {
        this(status, builder.getResponseContentTypeString(), BytesReference.bytes(builder));
    }
    /**
     * Creates a new plain text response.
     */
    public RestResponse(RestStatus status, String content) {
        this(status, TEXT_CONTENT_TYPE, new BytesArray(content));
    }