/**
 * Copyright 2017-2018 The OpenTracing Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package io.opentracing.contrib.spring.cloud.feign;

import feign.Client;
import feign.Request;
import feign.opentracing.FeignSpanDecorator;
import feign.opentracing.TracingClient;
import feign.opentracing.hystrix.TracingConcurrencyStrategy;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration;
import java.util.List;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author Pavol Loffay
 * @author Eddú Meléndez
 */
@Configuration
@ConditionalOnClass(Client.class)
@ConditionalOnBean(Tracer.class)
@AutoConfigureAfter(TracerAutoConfiguration.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)
@ConditionalOnProperty(name = "opentracing.spring.cloud.feign.enabled", havingValue = "true", matchIfMissing = true)
public class FeignTracingAutoConfiguration {

  @Autowired
  @Lazy
  private Tracer tracer;

  @Autowired(required = false)
  @Lazy
  private List<FeignSpanDecorator> spanDecorators;

  @Bean
  FeignContextBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory) {
    return new FeignContextBeanPostProcessor(tracer, beanFactory, spanDecorators);
  }

  @Configuration
  @ConditionalOnClass(name = {"com.netflix.hystrix.HystrixCommand", "feign.hystrix.HystrixFeign"})
  @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true")
  public static class HystrixFeign {

    @Autowired
    public HystrixFeign(Tracer tracer) {
      TracingConcurrencyStrategy.register(tracer);
    }
  }

  @Bean
  public TracingAspect tracingAspect() {
    return new TracingAspect();
  }

  /**
   * Trace feign clients created manually
   */
  @Aspect
  class TracingAspect {

    @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();
    }
  }
}

@@ -22,9 +22,9 @@
 -201
-8
+9
  The
@@ -1588,75 +1588,8 @@
 ty;%0A
-import org.springframework.cloud.openfeign.FeignAutoConfiguration;%0A
 impo
@@ -1632,24 +1632,24 @@
 ation.Bean;%0A
+
 import org.s
@@ -1803,16 +1803,39 @@
 el%C3%A9ndez%0A
+ * @author Gert Dubois%0A
  */%0A@Con
@@ -1984,16 +1984,60 @@
 eBefore(
+name = %22org.springframework.cloud.openfeign.
 FeignAut
@@ -2050,22 +2050,17 @@
 guration
-.class
+%22
 )%0A@Condi
@@ -2354,24 +2354,24 @@
 ators;%0A%0A
-
   @Bean%0A
   FeignC
@@ -2362,16 +2362,97 @@
   @Bean%0A
+  @ConditionalOnClass(name = %22org.springframework.cloud.openfeign.FeignContext%22)%0A
   FeignC

Fix for FeignTracingAutoConfiguration not loading correctly when feign-core dependency is present but spring-cloud-starter-openfeign dependency is not present (#243) (#244)