brave.httpclient.TracingHttpClientBuilder Java Examples

The following examples show how to use brave.httpclient.TracingHttpClientBuilder. 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: Catalog.java    From cxf with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/search")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject search(@QueryParam("q") final String query, @Context final TracerContext tracing) throws Exception {
    final CloseableHttpClient httpclient = TracingHttpClientBuilder
        .create(tracing.unwrap(HttpTracing.class))
        .build();

    try {
        final URI uri = new URIBuilder("https://www.googleapis.com/books/v1/volumes")
            .setParameter("q", query)
            .build();
        
        final HttpGet request = new HttpGet(uri);
        request.setHeader("Accept", "application/json");
        
        final HttpResponse response = httpclient.execute(request);
        final String data = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
        try (final StringReader reader = new StringReader(data)) {
            return Json.createReader(reader).readObject();
        }
    } finally {
        httpclient.close();
    }
}
 
Example #2
Source File: HelloService.java    From talk-kafka-zipkin with MIT License 5 votes vote down vote up
@Override
public void run(HelloServiceConfiguration configuration, Environment environment) {
	/* START TRACING INSTRUMENTATION */
	final var sender = URLConnectionSender.newBuilder()
			.endpoint(configuration.getZipkinEndpoint()).build();
	final var reporter = AsyncReporter.builder(sender).build();
	final var tracing = Tracing.newBuilder().localServiceName("hello-service")
			.sampler(Sampler.ALWAYS_SAMPLE).spanReporter(reporter).build();
	final var httpTracing = HttpTracing.newBuilder(tracing).build();
	final var jerseyTracingFilter = TracingApplicationEventListener
			.create(httpTracing);
	environment.jersey().register(jerseyTracingFilter);
	/* END TRACING INSTRUMENTATION */

	// Without instrumentation
	// final HttpClient httpClient =
	// new
	// HttpClientBuilder(environment).using(configuration.getHttpClientConfiguration())
	// .build(getName());
	final var httpClient = TracingHttpClientBuilder.create(httpTracing).build();
	final var url = configuration.getTranslationServiceUrl() + "/translate";
	final var translationServiceClient = new HelloTranslationServiceClient(httpClient,
			url);

	final var helloResource = new HelloResource(translationServiceClient);
	environment.jersey().register(helloResource);

	final var helloServiceHealthCheck = new HelloServiceHealthCheck();
	environment.healthChecks().register("hello-service", helloServiceHealthCheck);
}
 
Example #3
Source File: TracingConfiguration.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) {
  final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build();
  return new RestTemplateCustomizer() {
    @Override public void customize(RestTemplate restTemplate) {
      restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
    }
  };
}
 
Example #4
Source File: ApacheHttpClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    try (final CatalogTracing tracing = new CatalogTracing("catalog-client")) {
        final CloseableHttpClient httpclient = TracingHttpClientBuilder
                .create(tracing.getHttpTracing())
                .build();
    
        final HttpGet request = new HttpGet("http://localhost:9000/catalog");
        request.setHeader("Accept", "application/json");
        
        final HttpResponse response = httpclient.execute(request);
        System.out.println(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
        
        httpclient.close();
    }
}
 
Example #5
Source File: TracingConfiguration.java    From brave-webmvc-example with MIT License 5 votes vote down vote up
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) {
  final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build();
  return new RestTemplateCustomizer() {
    @Override public void customize(RestTemplate restTemplate) {
      restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
    }
  };
}
 
Example #6
Source File: TracingConfiguration.java    From txle with Apache License 2.0 4 votes vote down vote up
@Bean
RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) {
    final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build();
    return restTemplate -> restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
 
Example #7
Source File: TracingConfiguration.java    From txle with Apache License 2.0 4 votes vote down vote up
@Bean
RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) {
    final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build();
    return restTemplate -> restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
 
Example #8
Source File: HttpClientBraveIntegration.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Override
public HttpClientBuilder createBuilder() {
	return TracingHttpClientBuilder.create(httpTracing);
}
 
Example #9
Source File: TracingConfiguration.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
/** adds tracing to any underlying http client calls */
@Bean
HttpClient httpClient(HttpTracing httpTracing) {
    return TracingHttpClientBuilder.create(httpTracing).build();
}
 
Example #10
Source File: TraceWebClientAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
HttpClientBuilder traceHttpClientBuilder(HttpTracing httpTracing) {
	return TracingHttpClientBuilder.create(httpTracing);
}
 
Example #11
Source File: SpringWebFluxBenchmarks.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
protected CloseableHttpClient newClient(HttpTracing httpTracing) {
	return TracingHttpClientBuilder.create(httpTracing).disableAutomaticRetries()
			.build();
}
 
Example #12
Source File: TracingConfiguration.java    From brave-webmvc-example with MIT License 4 votes vote down vote up
/** adds tracing to any underlying http client calls */
@Bean HttpClient httpClient(HttpTracing httpTracing) {
  return TracingHttpClientBuilder.create(httpTracing).build();
}