use of com.linecorp.armeria.client.logging.LoggingClientBuilder in project zipkin by openzipkin.
the class HttpClientFactory method configureHttpLogging.
void configureHttpLogging(HttpLogging httpLogging, ClientOptionsBuilder options) {
if (httpLogging == HttpLogging.NONE)
return;
LoggingClientBuilder loggingBuilder = LoggingClient.builder().requestLogLevel(LogLevel.INFO).successfulResponseLogLevel(LogLevel.INFO).requestHeadersSanitizer((ctx, headers) -> {
if (!headers.contains(HttpHeaderNames.AUTHORIZATION)) {
return headers;
}
// TODO(anuraaga): Add unit tests after https://github.com/line/armeria/issues/2220
return headers.toBuilder().set(HttpHeaderNames.AUTHORIZATION, "****").build();
});
switch(httpLogging) {
case HEADERS:
loggingBuilder.contentSanitizer((ctx, unused) -> "");
break;
case BASIC:
loggingBuilder.contentSanitizer((ctx, unused) -> "");
loggingBuilder.headersSanitizer((ctx, unused) -> HttpHeaders.of());
break;
case BODY:
default:
break;
}
options.decorator(loggingBuilder.newDecorator());
if (httpLogging == HttpLogging.BODY) {
options.decorator(ContentPreviewingClient.newDecorator(Integer.MAX_VALUE));
}
}
use of com.linecorp.armeria.client.logging.LoggingClientBuilder in project curiostack by curioswitch.
the class LoggingModule method loggingClient.
@Provides
@Singleton
static Function<HttpClient, LoggingClient> loggingClient(LoggingConfig config, @RequestHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> requestHeaderSanitizers, @ResponseHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> responseHeaderSanitizers) {
LoggingClientBuilder builder = LoggingClient.builder();
configureLoggingDecorator(builder, config, requestHeaderSanitizers, responseHeaderSanitizers);
if (config.getLogAllClientRequests()) {
builder.requestLogLevel(LogLevel.INFO);
builder.successfulResponseLogLevel(LogLevel.INFO);
}
return builder::build;
}
use of com.linecorp.armeria.client.logging.LoggingClientBuilder in project zipkin by openzipkin.
the class ElasticsearchExtension method computeStorageBuilder.
Builder computeStorageBuilder() {
WebClientBuilder builder = WebClient.builder(baseUrl()).factory(ClientFactory.builder().useHttp2Preface(false).build());
builder.decorator((delegate, ctx, req) -> {
final HttpResponse response = delegate.execute(ctx, req);
return HttpResponse.from(response.aggregate().thenApply(r -> {
// ES will return a 'warning' response header when using deprecated api, detect this and
// fail early so we can do something about it.
// Example usage: https://github.com/elastic/elasticsearch/blob/3049e55f093487bb582a7e49ad624961415ba31c/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/IndexPrivilegeIntegTests.java#L559
final String warningHeader = r.headers().get("warning");
if (warningHeader != null) {
if (IGNORE_THESE_WARNINGS.stream().noneMatch(p -> p.matcher(warningHeader).find())) {
throw new IllegalArgumentException("Detected usage of deprecated API for request " + req.toString() + ":\n" + warningHeader);
}
}
// Convert AggregatedHttpResponse back to HttpResponse.
return r.toHttpResponse();
}));
});
// com.linecorp.armeria.client.logging
if (Boolean.parseBoolean(System.getenv("ES_DEBUG"))) {
ClientOptionsBuilder options = ClientOptions.builder();
LoggingClientBuilder loggingBuilder = LoggingClient.builder().requestLogLevel(LogLevel.INFO).successfulResponseLogLevel(LogLevel.INFO);
options.decorator(loggingBuilder.newDecorator());
options.decorator(ContentPreviewingClient.newDecorator(Integer.MAX_VALUE));
builder.options(options.build());
}
WebClient client = builder.build();
return ElasticsearchStorage.newBuilder(new ElasticsearchStorage.LazyHttpClient() {
@Override
public WebClient get() {
return client;
}
@Override
public void close() {
client.endpointGroup().close();
}
@Override
public String toString() {
return client.uri().toString();
}
}).index("zipkin-test").flushOnWrites(true);
}
Aggregations