content: /*
   * Copyright The OpenTelemetry Authors
   * SPDX-License-Identifier: Apache-2.0
   */
  
  package io.opentelemetry.javaagent.instrumentation.rocketmqclient.v4_8;
  
  import static net.bytebuddy.matcher.ElementMatchers.isMethod;
  import static net.bytebuddy.matcher.ElementMatchers.named;
  import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
  
  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.rocketmq.client.consumer.DefaultMQPushConsumer;
  import org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl;
  
  public class RocketMqConsumerInstrumentation implements TypeInstrumentation {
  
    @Override
    public ElementMatcher<TypeDescription> typeMatcher() {
      return named("org.apache.rocketmq.client.consumer.DefaultMQPushConsumer");
    }
  
    @Override
    public void transform(TypeTransformer transformer) {
      transformer.applyAdviceToMethod(
          isMethod().and(named("start")).and(takesArguments(0)),
          RocketMqConsumerInstrumentation.class.getName() + "$StartAdvice");
    }
  
    @SuppressWarnings("unused")
    public static class StartAdvice {
      @Advice.OnMethodEnter(suppress = Throwable.class)
      public static void onEnter(
          @Advice.FieldValue(
                  value = "defaultMQPushConsumerImpl",
                  declaringType = DefaultMQPushConsumer.class)
              DefaultMQPushConsumerImpl defaultMqPushConsumerImpl) {
        defaultMqPushConsumerImpl.registerConsumeMessageHook(
            RocketMqClientHooks.CONSUME_MESSAGE_HOOK);
      }
    }
  }
  