open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.96k stars 860 forks source link

TypeInstrumentation why cannot SpringBoot RedisOperations. ConvertAndSend to intercept #11867

Closed 1095071913 closed 3 months ago

1095071913 commented 3 months ago

Describe the bug

TypeInstrumentation why cannot SpringBoot RedisOperations. ConvertAndSend to intercept

agent code:

public class RedisPublishInstrumentation implements TypeInstrumentation {

    @Override
    public ElementMatcher<TypeDescription> typeMatcher() {
        return implementsInterface(named("org.springframework.data.redis.core.RedisOperations"));
    }

    @Override
    public void transform(TypeTransformer transformer) {
        transformer.applyAdviceToMethod(
            isMethod()
                .and(named("convertAndSend")),
            RedisPublishInstrumentation.class.getName() + "$RedisPublishAdvice");
    }

    public static class RedisPublishAdvice {

        @Advice.OnMethodEnter(suppress = Throwable.class)
        public static void onEnter() {

        }

        @Advice.OnMethodExit(suppress = Throwable.class)
        public static void after() {
        }

    }

}

springboot demo:

private final StringRedisTemplate stringRedisTemplate;

@Override
public void distribute(MessageDO messageDO) {
  stringRedisTemplate.convertAndSend(RedisWebsocketMessageListener.CHANNEL, "test");
}

maven:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
      <version>3.2.6</version>
    </dependency>

What should I do to intercept

Steps to reproduce

TypeInstrumentation why cannot SpringBoot RedisOperations. ConvertAndSend to intercept

Expected behavior

success

Actual behavior

error

Javaagent or library instrumentation version

https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/tag/v2.4.0

Environment

JDK: OS:

Additional context

No response

1095071913 commented 3 months ago

@laurit Can you help me look at this problem

laurit commented 3 months ago

By default certain classes are excluded from instrumentation. Have a look at https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/2a35b8d7594374bcc2ee122fc2fe58760f93b617/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/AdditionalLibraryIgnoredTypesConfigurer.java#L82 You can override this by calling allowClass in your own IgnoredTypesConfigurer.

1095071913 commented 3 months ago

By default certain classes are excluded from instrumentation. Have a look at

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/2a35b8d7594374bcc2ee122fc2fe58760f93b617/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/AdditionalLibraryIgnoredTypesConfigurer.java#L82

You can override this by calling allowClass in your own IgnoredTypesConfigurer.

Thank you for your help, it has been solved through your program