use of io.servicetalk.http.api.HttpResponseStatus.StatusClass.SUCCESSFUL_2XX in project servicetalk by apple.
the class HttpReporter method encodedSpansReporter.
private static Function<Buffer, Completable> encodedSpansReporter(final HttpClient client, final Codec codec) {
final String path;
final CharSequence contentType;
switch(codec) {
case JSON_V1:
path = V1_PATH;
contentType = APPLICATION_JSON;
break;
case JSON_V2:
path = V2_PATH;
contentType = APPLICATION_JSON;
break;
case THRIFT:
path = V2_PATH;
contentType = THRIFT_CONTENT_TYPE;
break;
case PROTO3:
path = V2_PATH;
contentType = PROTO_CONTENT_TYPE;
break;
default:
throw new IllegalArgumentException("Unknown codec: " + codec);
}
return encodedSpans -> client.request(client.post(path).setHeader(CONTENT_TYPE, contentType).payloadBody(encodedSpans)).beforeOnSuccess(response -> {
HttpResponseStatus status = response.status();
if (status.statusClass() != SUCCESSFUL_2XX) {
LOGGER.info("Unexpected response from the collector. Response headers: {}", response.toString((__, headerValue) -> headerValue));
}
}).ignoreElement().onErrorComplete(cause -> {
LOGGER.error("Failed to send a span, ignoring.", cause);
return true;
});
}
Aggregations