content: /*
   * Copyright The OpenTelemetry Authors
   * SPDX-License-Identifier: Apache-2.0
   */
  
  package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route;
  
  import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
  import static net.bytebuddy.matcher.ElementMatchers.named;
  
  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 org.apache.pekko.http.scaladsl.server.RequestContext;
  import org.apache.pekko.http.scaladsl.server.RouteResult;
  import scala.Function1;
  import scala.concurrent.Future;
  
  public class RouteConcatenationInstrumentation implements TypeInstrumentation {
    @Override
    public ElementMatcher<TypeDescription> typeMatcher() {
      return named("org.apache.pekko.http.scaladsl.server.RouteConcatenation$RouteWithConcatenation");
    }
  
    @Override
    public void transform(TypeTransformer transformer) {
      transformer.applyAdviceToMethod(isConstructor(), this.getClass().getName() + "$ApplyAdvice");
      transformer.applyAdviceToMethod(named("$tilde"), this.getClass().getName() + "$ApplyAdvice");
    }
  
    @SuppressWarnings("unused")
    public static class ApplyAdvice {
  
      @Advice.OnMethodEnter(suppress = Throwable.class)
      public static void onEnter(
          @Advice.Argument(value = 0, readOnly = false)
              Function1<RequestContext, Future<RouteResult>> route) {
        route = new PekkoRouteWrapper(route);
      }
    }
  }
  