use of com.linecorp.armeria.client.ClientOptionsBuilder in project zipkin by openzipkin.
the class ZipkinElasticsearchStorageConfiguration method esTracing.
@Bean
@Qualifier(QUALIFIER)
@ConditionalOnSelfTracing
Consumer<ClientOptionsBuilder> esTracing(Optional<HttpTracing> maybeHttpTracing) {
if (!maybeHttpTracing.isPresent()) {
// Alternatively, check why we would ever get here if ConditionalOnSelfTracing matches
return client -> {
};
}
HttpTracing httpTracing = maybeHttpTracing.get().clientOf("elasticsearch");
SpanCustomizer spanCustomizer = CurrentSpanCustomizer.create(httpTracing.tracing());
return client -> {
client.decorator((delegate, ctx, req) -> {
// We only need the name if it's available and can unsafely access the partially filled log.
RequestLog log = ctx.log().partial();
if (log.isAvailable(RequestLogProperty.NAME)) {
String name = log.name();
if (name != null) {
// override the span name if set
spanCustomizer.name(name);
}
}
return delegate.execute(ctx, req);
});
// the tracing decorator is added last so that it encloses the attempt to overwrite the name.
client.decorator(BraveClient.newDecorator(httpTracing));
};
}
use of com.linecorp.armeria.client.ClientOptionsBuilder 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