content: /*
   * Copyright The OpenTelemetry Authors
   * SPDX-License-Identifier: Apache-2.0
   */
  
  package io.opentelemetry.javaagent.instrumentation.ratpack.v1_7;
  
  import static net.bytebuddy.matcher.ElementMatchers.isMethod;
  import static net.bytebuddy.matcher.ElementMatchers.isStatic;
  import static net.bytebuddy.matcher.ElementMatchers.named;
  import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
  
  import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
  import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
  import net.bytebuddy.asm.Advice;
  import net.bytebuddy.description.type.TypeDescription;
  import net.bytebuddy.matcher.ElementMatcher;
  import ratpack.http.client.HttpClient;
  
  public class HttpClientInstrumentation implements TypeInstrumentation {
  
    @Override
    public ElementMatcher<TypeDescription> typeMatcher() {
      return named("ratpack.http.client.HttpClient");
    }
  
    @Override
    public void transform(TypeTransformer transformer) {
      transformer.applyAdviceToMethod(
          isMethod()
              .and(isStatic())
              .and(named("of"))
              .and(takesArgument(0, named("ratpack.func.Action"))),
          HttpClientInstrumentation.class.getName() + "$OfAdvice");
    }
  
    @SuppressWarnings("unused")
    public static class OfAdvice {
  
      @Advice.OnMethodExit(suppress = Throwable.class)
      @Advice.AssignReturned.ToReturned
      public static HttpClient injectTracing(@Advice.Return HttpClient httpClient) throws Exception {
        return RatpackSingletons.httpClient().instrument(httpClient);
      }
    }
  }
  