// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java
// public class SpanFinishingFilter implements Filter {
// 
//   public SpanFinishingFilter() {
//   }
// 
//   /**
//    * @param tracer
//    * @deprecated use no-args constructor
//    */
//   @Deprecated
//   public SpanFinishingFilter(Tracer tracer){
//   }
// 
//   @Override
//   public void init(FilterConfig filterConfig) {
//   }
// 
//   @Override
//   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
//       throws IOException, ServletException {
// 
//     HttpServletResponse httpResponse = (HttpServletResponse)response;
//     HttpServletRequest httpRequest = (HttpServletRequest)request;
// 
//     try {
//       chain.doFilter(request, response);
//     } catch (Exception ex) {
//       SpanWrapper spanWrapper = getSpanWrapper(httpRequest);
//       if (spanWrapper != null) {
//         Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus());
//         addExceptionLogs(spanWrapper.get(), ex);
//       }
//       throw ex;
//     } finally {
//       SpanWrapper spanWrapper = getSpanWrapper(httpRequest);
//       if (spanWrapper != null) {
//         spanWrapper.getScope().close();
//         if (request.isAsyncStarted()) {
//           request.getAsyncContext().addListener(new SpanFinisher(spanWrapper), request, response);
//         } else {
//           spanWrapper.finish();
//         }
//       }
//     }
//   }
// 
//   private SpanWrapper getSpanWrapper(HttpServletRequest request) {
//     return CastUtils.cast(request.getAttribute(SpanWrapper.PROPERTY_NAME), SpanWrapper.class);
//   }
// 
//   @Override
//   public void destroy() {
//   }
// 
//   static class SpanFinisher implements AsyncListener {
//     private SpanWrapper spanWrapper;
//     SpanFinisher(SpanWrapper spanWrapper) {
//       this.spanWrapper = spanWrapper;
//     }
// 
//     @Override
//     public void onComplete(AsyncEvent event) throws IOException {
//       HttpServletResponse httpResponse = (HttpServletResponse)event.getSuppliedResponse();
//       if (httpResponse.getStatus() >= 500) {
//         addExceptionLogs(spanWrapper.get(), event.getThrowable());
//       }
//       Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus());
//       spanWrapper.finish();
//     }
//     @Override
//     public void onTimeout(AsyncEvent event) throws IOException {
//     }
//     @Override
//     public void onError(AsyncEvent event) throws IOException {
//       // this handler is called when exception is thrown in async handler
//       // note that exception logs are added in filter not here
//     }
//     @Override
//     public void onStartAsync(AsyncEvent event) throws IOException {
//     }
//   }
// 
//   private static void addExceptionLogs(Span span, Throwable throwable) {
//     Tags.ERROR.set(span, true);
//     if (throwable != null) {
//       Map<String, Object> errorLogs = new HashMap<>(2);
//       errorLogs.put("event", Tags.ERROR.getKey());
//       errorLogs.put("error.object", throwable);
//       span.log(errorLogs);
//     }
//   }
// }


import io.opentracing.Tracer;
import io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter;
import javax.servlet.DispatcherType;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
package io.opentracing.contrib.jaxrs2.example.spring.boot;


/**
 * @author Pavol Loffay
 */
@org.springframework.context.annotation.Configuration
public class Configuration {

    @Bean
    public Tracer tracer() {
        return new LoggingTracer();
    }

    @Bean
    public FilterRegistrationBean spanFinishingFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java
// public class SpanFinishingFilter implements Filter {
// 
//   public SpanFinishingFilter() {
//   }
// 
//   /**
//    * @param tracer
//    * @deprecated use no-args constructor
//    */
//   @Deprecated
//   public SpanFinishingFilter(Tracer tracer){
//   }
// 
//   @Override
//   public void init(FilterConfig filterConfig) {
//   }
// 
//   @Override
//   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
//       throws IOException, ServletException {
// 
//     HttpServletResponse httpResponse = (HttpServletResponse)response;
//     HttpServletRequest httpRequest = (HttpServletRequest)request;
// 
//     try {
//       chain.doFilter(request, response);
//     } catch (Exception ex) {
//       SpanWrapper spanWrapper = getSpanWrapper(httpRequest);
//       if (spanWrapper != null) {
//         Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus());
//         addExceptionLogs(spanWrapper.get(), ex);
//       }
//       throw ex;
//     } finally {
//       SpanWrapper spanWrapper = getSpanWrapper(httpRequest);
//       if (spanWrapper != null) {
//         spanWrapper.getScope().close();
//         if (request.isAsyncStarted()) {
//           request.getAsyncContext().addListener(new SpanFinisher(spanWrapper), request, response);
//         } else {
//           spanWrapper.finish();
//         }
//       }
//     }
//   }
// 
//   private SpanWrapper getSpanWrapper(HttpServletRequest request) {
//     return CastUtils.cast(request.getAttribute(SpanWrapper.PROPERTY_NAME), SpanWrapper.class);
//   }
// 
//   @Override
//   public void destroy() {
//   }
// 
//   static class SpanFinisher implements AsyncListener {
//     private SpanWrapper spanWrapper;
//     SpanFinisher(SpanWrapper spanWrapper) {
//       this.spanWrapper = spanWrapper;
//     }
// 
//     @Override
//     public void onComplete(AsyncEvent event) throws IOException {
//       HttpServletResponse httpResponse = (HttpServletResponse)event.getSuppliedResponse();
//       if (httpResponse.getStatus() >= 500) {
//         addExceptionLogs(spanWrapper.get(), event.getThrowable());
//       }
//       Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus());
//       spanWrapper.finish();
//     }
//     @Override
//     public void onTimeout(AsyncEvent event) throws IOException {
//     }
//     @Override
//     public void onError(AsyncEvent event) throws IOException {
//       // this handler is called when exception is thrown in async handler
//       // note that exception logs are added in filter not here
//     }
//     @Override
//     public void onStartAsync(AsyncEvent event) throws IOException {
//     }
//   }
// 
//   private static void addExceptionLogs(Span span, Throwable throwable) {
//     Tags.ERROR.set(span, true);
//     if (throwable != null) {
//       Map<String, Object> errorLogs = new HashMap<>(2);
//       errorLogs.put("event", Tags.ERROR.getKey());
//       errorLogs.put("error.object", throwable);
//       span.log(errorLogs);
//     }
//   }
// }


// Path: examples/spring-boot/src/main/java/io/opentracing/contrib/jaxrs2/example/spring/boot/Configuration.java
import io.opentracing.Tracer;
import io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter;
import javax.servlet.DispatcherType;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

package io.opentracing.contrib.jaxrs2.example.spring.boot;


/**
 * @author Pavol Loffay
 */
@org.springframework.context.annotation.Configuration
public class Configuration {

    @Bean
    public Tracer tracer() {
        return new LoggingTracer();
    }

    @Bean
    public FilterRegistrationBean spanFinishingFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new SpanFinishingFilter());