feign.opentracing.TracingClient Java Examples

The following examples show how to use feign.opentracing.TracingClient. 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: TracedFeignBeanFactory.java    From java-spring-cloud with Apache License 2.0 6 votes vote down vote up
public Object from(Object bean) {
  if (bean instanceof TracingClient || bean instanceof LoadBalancedTracedFeign) {
    return bean;
  }

  if (bean instanceof Client) {
    if (bean instanceof LoadBalancerFeignClient) {
      return new LoadBalancedTracedFeign(
          buildTracingClient(((LoadBalancerFeignClient) bean).getDelegate(), tracer),
          beanFactory.getBean(CachingSpringLoadBalancerFactory.class),
          beanFactory.getBean(SpringClientFactory.class));
    }
    return buildTracingClient((Client) bean, tracer);
  }

  return bean;
}
 
Example #2
Source File: TracingConfiguration.java    From hola with Apache License 2.0 6 votes vote down vote up
/**
 * This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a REST endpoint with
 * Hystrix fallback support.
 *
 * @return The feign pointing to the service URL and with Hystrix fallback.
 */
@Produces
@Singleton
private AlohaService alohaService(Tracer tracer) {
    // bind current span to Hystrix thread
    TracingConcurrencyStrategy.register();

    return HystrixFeign.builder()
            // Use apache HttpClient which contains the ZipKin Interceptors
            .client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))

            // Bind Zipkin Server Span to Feign Thread
            .logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
            .decoder(new JacksonDecoder())
            .target(AlohaService.class,"http://aloha:8080/",
                    () -> Collections.singletonList("Aloha response (fallback)"));
}
 
Example #3
Source File: FeignTracingAutoConfiguration.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Around("execution (* feign.Client.*(..)) && !within(is(FinalType))")
public Object feignClientWasCalled(final ProceedingJoinPoint pjp) throws Throwable {
  Object bean = pjp.getTarget();
  if (!(bean instanceof TracingClient)) {
    Object[] args = pjp.getArgs();
    return new TracingClientBuilder((Client) bean, tracer)
        .withFeignSpanDecorators(spanDecorators)
        .build()
        .execute((Request) args[0], (Request.Options) args[1]);
  }
  return pjp.proceed();
}
 
Example #4
Source File: HystrixFeignTracingTest.java    From feign-opentracing with Apache License 2.0 5 votes vote down vote up
@Override
protected Feign getClient() {
    return feign  = HystrixFeign.builder()
            .client(new TracingClient(new Client.Default(null, null), mockTracer))
            .retryer(new Retryer.Default(100, SECONDS.toMillis(1), FeignTracingTest.NUMBER_OF_RETRIES))
            .build();
}
 
Example #5
Source File: TracingConfiguration.java    From ola with Apache License 2.0 5 votes vote down vote up
/**
 *
 * This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a
 * REST endpoint with Hystrix fallback support.
 */
@Bean
public HolaService holaService(Tracer tracer) {
    // bind current span to Hystrix thread
    TracingConcurrencyStrategy.register();

    return HystrixFeign.builder()
            .client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
            .logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
            .decoder(new JacksonDecoder())
            .target(HolaService.class, "http://hola:8080/",
                    () -> Collections.singletonList("Hola response (fallback)"));
}
 
Example #6
Source File: Catalog.java    From cxf with Apache License 2.0 5 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 GoogleBooksApi api = Feign
        .builder()
        .client(new TracingClient(new ApacheHttpClient(), tracing.unwrap(Tracer.class)))
        .target(GoogleBooksApi.class, "https://www.googleapis.com");
 
    final feign.Response response = api.search(query);
    try (final Reader reader = response.body().asReader()) {
        return Json.createReader(reader).readObject();
    }
}
 
Example #7
Source File: TracedFeignBeanFactory.java    From java-spring-cloud with Apache License 2.0 4 votes vote down vote up
private TracingClient buildTracingClient(Client delegate, Tracer tracer) {
  return new io.opentracing.contrib.spring.cloud.feign.TracingClientBuilder(delegate, tracer)
      .withFeignSpanDecorators(spanDecorators)
      .build();
}
 
Example #8
Source File: TracingClientBuilder.java    From java-spring-cloud with Apache License 2.0 4 votes vote down vote up
TracingClient build() {
  if (decorators == null || decorators.isEmpty()) {
    return new TracingClient(delegate, tracer);
  }
  return new TracingClient(delegate, tracer, decorators);
}