Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ClassNotFoundException when resteasy-spring attempts to process tracer-related beans #4921

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;

/**
Expand All @@ -14,6 +15,11 @@ public static void register(Class<?> beanClass) {
ddBeanClasses.put(beanClass.getName(), beanClass);
}

public static boolean isDatadogBean(BeanDefinition beanDefinition) {
String className = beanDefinition.getBeanClassName();
return null != className && ddBeanClasses.containsKey(className);
}

public static void repair(RootBeanDefinition beanDefinition) {
if (!beanDefinition.hasBeanClass()) {
String className = beanDefinition.getBeanClassName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public String instrumentedType() {
return "org.jboss.resteasy.plugins.spring.SpringBeanProcessor";
}

@Override
public String[] helperClassNames() {
return new String[] {packageName + ".BeanDefinitionRepairer"};
}

@Override
public void adviceTransformations(AdviceTransformation transformation) {
transformation.applyAdvice(
Expand All @@ -45,8 +50,7 @@ public String muzzleDirective() {
public static class SkipBeanClassAdvice {
@Advice.OnMethodEnter(skipOn = Advice.OnNonDefaultValue.class, suppress = Throwable.class)
public static Class<?> onEnter(@Advice.Argument(3) final BeanDefinition beanDefinition) {
if ("datadog.trace.instrumentation.springweb.HandlerMappingResourceNameFilter"
.equals(beanDefinition.getBeanClassName())) {
if (BeanDefinitionRepairer.isDatadogBean(beanDefinition)) {
return Object.class; // skip the original method and return this value instead
} else {
return null; // continue on to call the original method and return its value
Expand Down