org.eclipse.microprofile.opentracing.ClientTracingRegistrar Java Examples

The following examples show how to use org.eclipse.microprofile.opentracing.ClientTracingRegistrar. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientSetup.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private ClientBuilder createClient(final ExecutorService executor, final Optional<String> keystoreLocation,
        final Optional<String> keystoreType, final String keystorePassword, final Optional<String> truststoreType,
        final List<String> serverHostnames) {
    final ClientBuilder builder = ClientBuilder.newBuilder();
    builder.connectTimeout(connectTimeout, MILLISECONDS);
    builder.readTimeout(readTimeout, MILLISECONDS);
    builder.executorService(executor);
    if (acceptAnyCertificate) {
        builder.hostnameVerifier((host, session) -> true);
        builder.sslContext(createUnsafeSSLContext());
    } else if (keystoreLocation.isPresent()) {
        builder.hostnameVerifier((host, session) -> serverHostnames.contains(host));
        builder.sslContext(createSSLContext(keystoreLocation, keystoreType, keystorePassword, truststoreType));
    }
    providers.map(it -> Stream.of(it.split(",")).map(String::trim).filter(v -> !v.isEmpty()).map(fqn -> {
        try {
            return Thread.currentThread().getContextClassLoader().loadClass(fqn).getConstructor().newInstance();
        } catch (final Exception e) {
            log.warn("Can't add provider " + fqn + ": " + e.getMessage(), e);
            return null;
        }
    }).filter(Objects::nonNull)).ifPresent(it -> it.forEach(builder::register));
    return ClientTracingRegistrar.configure(builder);
}
 
Example #2
Source File: TestServerWebServices.java    From microprofile-opentracing with Apache License 2.0 5 votes vote down vote up
/**
 * Execute a nested web service call.
 * @param requestUrl The request URL.
 */
private void executeNested(String requestUrl) {
    Client restClient = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
    WebTarget target = restClient.target(requestUrl);
    Response nestedResponse = target.request().get();
    nestedResponse.close();
}
 
Example #3
Source File: MyService.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Traced
public String call() {
    // tag::client-registration[]
    Client client = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
    // end::client-registration[]
    try {
        String response = client.target("http://localhost:8080")
                .path("/simple")
                .request()
                .get(String.class);
        return "Called an external service successfully, it responded: " + response;
    } finally {
        client.close();
    }
}
 
Example #4
Source File: TestClientRegistrarWebServices.java    From microprofile-opentracing with Apache License 2.0 4 votes vote down vote up
private Client instrumentedClient() {
    ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    ClientTracingRegistrar.configure(clientBuilder);
    return clientBuilder.build();
}
 
Example #5
Source File: TestClientRegistrarWebServices.java    From microprofile-opentracing with Apache License 2.0 4 votes vote down vote up
private Client instrumentedClientExecutor() {
    ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    ClientTracingRegistrar.configure(clientBuilder, Executors.newFixedThreadPool(10));
    return clientBuilder.build();
}
 
Example #6
Source File: TestServerWebServices.java    From microprofile-opentracing with Apache License 2.0 4 votes vote down vote up
/**
 * Execute a nested web service call asynchronously.
 * @param requestUrl The request URL.
 * @return Future for the Response.
 */
private Future<Response> executeNestedAsync(String requestUrl) {
    Client restClient = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
    WebTarget target = restClient.target(requestUrl);
    return target.request().async().get();
}