// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }


import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.tag.Tags;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 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.aop;


public abstract class BaseTracingAspect {

  private static final Logger log = LoggerFactory.getLogger(BaseTracingAspect.class);
  private final Tracer tracer;
  private final Class<? extends Annotation> annotation;
  private final List<MethodInterceptorSpanDecorator> decorators;
  private Pattern skipPattern;

  public BaseTracingAspect(Tracer tracer, List<MethodInterceptorSpanDecorator> decorators,
      Class<? extends Annotation> annotation, Pattern skipPattern) {
    this.tracer = tracer;
    this.decorators = decorators != null ? decorators : new ArrayList<>();
    this.annotation = annotation;
    this.skipPattern = skipPattern;
  }

  /**
   * This method should be overridden to add the proper annotation and call {@link
   * BaseTracingAspect#internalTrace(ProceedingJoinPoint)}
   */
  public abstract Object trace(ProceedingJoinPoint pjp) throws Throwable;

  protected Object internalTrace(ProceedingJoinPoint pjp) throws Throwable {
    if (skipPattern.matcher(pjp.getTarget().getClass().getName()).matches()) {
      return pjp.proceed();
    }

    // operation name is method name
    Span span = tracer.buildSpan(getOperationName(pjp))
        .withTag(Tags.COMPONENT.getKey(), getComponent(pjp))
        .withTag(ExtensionTags.CLASS_TAG.getKey(), pjp.getTarget().getClass().getSimpleName())
// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }


// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/aop/BaseTracingAspect.java
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.tag.Tags;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 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.aop;


public abstract class BaseTracingAspect {

  private static final Logger log = LoggerFactory.getLogger(BaseTracingAspect.class);
  private final Tracer tracer;
  private final Class<? extends Annotation> annotation;
  private final List<MethodInterceptorSpanDecorator> decorators;
  private Pattern skipPattern;

  public BaseTracingAspect(Tracer tracer, List<MethodInterceptorSpanDecorator> decorators,
      Class<? extends Annotation> annotation, Pattern skipPattern) {
    this.tracer = tracer;
    this.decorators = decorators != null ? decorators : new ArrayList<>();
    this.annotation = annotation;
    this.skipPattern = skipPattern;
  }

  /**
   * This method should be overridden to add the proper annotation and call {@link
   * BaseTracingAspect#internalTrace(ProceedingJoinPoint)}
   */
  public abstract Object trace(ProceedingJoinPoint pjp) throws Throwable;

  protected Object internalTrace(ProceedingJoinPoint pjp) throws Throwable {
    if (skipPattern.matcher(pjp.getTarget().getClass().getName()).matches()) {
      return pjp.proceed();
    }

    // operation name is method name
    Span span = tracer.buildSpan(getOperationName(pjp))
        .withTag(Tags.COMPONENT.getKey(), getComponent(pjp))
        .withTag(ExtensionTags.CLASS_TAG.getKey(), pjp.getTarget().getClass().getSimpleName())
        .withTag(ExtensionTags.METHOD_TAG.getKey(), pjp.getSignature().getName())