Support muzzle testInverse = true
MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/core-3.5.gradle
dd-java-agent/instrumentation/hibernate/core-3.5/core-3.5.gradle
@@ -16,7 +16,8 @@ muzzle {
pass {
group = "org.hibernate"
module = "hibernate-core"
- versions = "[3.5.0-Final,4.0.0.Final)"
+ versions = "[3.3.2.GA,4.0.0.Final)"
+ assertInverse = true
}
}
@@ -31,7 +32,7 @@ testSets {
}
dependencies {
- compileOnly group: 'org.hibernate', name: 'hibernate-core', version: '3.5.0-Final'
+ compileOnly group: 'org.hibernate', name: 'hibernate-core', version: '3.3.2.GA'
compile project(':dd-java-agent:agent-tooling')
compile project(':dd-java-agent:instrumentation:hibernate')
@@ -44,7 +45,7 @@ dependencies {
testCompile project(':dd-java-agent:testing')
testCompile project(':dd-java-agent:instrumentation:jdbc')
- testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.5.0-Final'
+ testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.3.2.GA'
testCompile group: 'org.hibernate', name: 'hibernate-annotations', version: '+'
testCompile group: 'javassist', name: 'javassist', version: '+'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/AbstractHibernateInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/AbstractHibernateInstrumentation.java
package datadog.trace.instrumentation.hibernate.core.v3_5;
-import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
-import static net.bytebuddy.matcher.ElementMatchers.not;
-
import datadog.trace.agent.tooling.Instrumenter;
-import net.bytebuddy.matcher.ElementMatcher;
+import org.hibernate.EntityNameResolver;
+import org.hibernate.classic.Validatable;
public abstract class AbstractHibernateInstrumentation extends Instrumenter.Default {
@@ -22,12 +20,23 @@ public abstract class AbstractHibernateInstrumentation extends Instrumenter.Defa
"datadog.trace.agent.decorator.DatabaseClientDecorator",
"datadog.trace.agent.decorator.OrmClientDecorator",
"datadog.trace.instrumentation.hibernate.HibernateDecorator",
+ packageName + ".AbstractHibernateInstrumentation$V3Advice",
};
}
- @Override
- public ElementMatcher<ClassLoader> classLoaderMatcher() {
- return not(classLoaderHasClasses("org.hibernate.SharedSessionContract"))
- .and(classLoaderHasClasses("org.hibernate.EntityNameResolver"));
+ public abstract static class V3Advice {
+
+ /**
+ * Some cases of instrumentation will match more broadly than others, so this unused method
+ * allows all instrumentation to uniformly match versions of Hibernate between 3.5 and 4.
+ */
+ public static void muzzleCheck(
+ // Not in 4.0
+ final Validatable validatable,
+ // Not before 3.2.0.GA (Can't find anything not before 3.5)
+ final EntityNameResolver resolver) {
+ validatable.validate();
+ resolver.resolveEntityName(null);
+ }
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/CriteriaInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/CriteriaInstrumentation.java
@@ -41,7 +41,7 @@ public class CriteriaInstrumentation extends AbstractHibernateInstrumentation {
CriteriaMethodAdvice.class.getName());
}
- public static class CriteriaMethodAdvice {
+ public static class CriteriaMethodAdvice extends V3Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/QueryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/QueryInstrumentation.java
@@ -48,7 +48,7 @@ public class QueryInstrumentation extends AbstractHibernateInstrumentation {
QueryMethodAdvice.class.getName());
}
- public static class QueryMethodAdvice {
+ public static class QueryMethodAdvice extends V3Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/SessionFactoryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/SessionFactoryInstrumentation.java
@@ -57,7 +57,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
SessionFactoryAdvice.class.getName());
}
- public static class SessionFactoryAdvice {
+ public static class SessionFactoryAdvice extends V3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return final Object session) {

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/SessionInstrumentation.java
@@ -107,7 +107,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
return transformers;
}
- public static class SessionCloseAdvice {
+ public static class SessionCloseAdvice extends V3Advice {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void closeSession(
@@ -138,7 +138,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class SessionMethodAdvice {
+ public static class SessionMethodAdvice extends V3Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(
@@ -171,7 +171,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetQueryAdvice {
+ public static class GetQueryAdvice extends V3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getQuery(
@@ -193,7 +193,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetTransactionAdvice {
+ public static class GetTransactionAdvice extends V3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getTransaction(
@@ -216,7 +216,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetCriteriaAdvice {
+ public static class GetCriteriaAdvice extends V3Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getCriteria(

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/TransactionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.5/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_5/TransactionInstrumentation.java
@@ -41,7 +41,7 @@ public class TransactionInstrumentation extends AbstractHibernateInstrumentation
TransactionCommitAdvice.class.getName());
}
- public static class TransactionCommitAdvice {
+ public static class TransactionCommitAdvice extends V3Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startCommit(@Advice.This final Transaction transaction) {

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/core-4.0.gradle
dd-java-agent/instrumentation/hibernate/core-4.0/core-4.0.gradle
@@ -10,6 +10,7 @@ muzzle {
group = "org.hibernate"
module = "hibernate-core"
versions = "[4.0.0.Final,)"
+ assertInverse = true
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/AbstractHibernateInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/AbstractHibernateInstrumentation.java
package datadog.trace.instrumentation.hibernate.core.v4_0;
-import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
-
import datadog.trace.agent.tooling.Instrumenter;
-import net.bytebuddy.matcher.ElementMatcher;
+import org.hibernate.SharedSessionContract;
public abstract class AbstractHibernateInstrumentation extends Instrumenter.Default {
@@ -21,11 +19,18 @@ public abstract class AbstractHibernateInstrumentation extends Instrumenter.Defa
"datadog.trace.agent.decorator.DatabaseClientDecorator",
"datadog.trace.agent.decorator.OrmClientDecorator",
"datadog.trace.instrumentation.hibernate.HibernateDecorator",
+ packageName + ".AbstractHibernateInstrumentation$V4Advice",
};
}
- @Override
- public ElementMatcher<ClassLoader> classLoaderMatcher() {
- return classLoaderHasClasses("org.hibernate.SharedSessionContract");
+ public abstract static class V4Advice {
+
+ /**
+ * Some cases of instrumentation will match more broadly than others, so this unused method
+ * allows all instrumentation to uniformly match versions of Hibernate starting at 4.0.
+ */
+ public static void muzzleCheck(final SharedSessionContract contract) {
+ contract.createCriteria("");
+ }
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/CriteriaInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/CriteriaInstrumentation.java
@@ -41,7 +41,7 @@ public class CriteriaInstrumentation extends AbstractHibernateInstrumentation {
CriteriaMethodAdvice.class.getName());
}
- public static class CriteriaMethodAdvice {
+ public static class CriteriaMethodAdvice extends V4Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/QueryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/QueryInstrumentation.java
@@ -48,7 +48,7 @@ public class QueryInstrumentation extends AbstractHibernateInstrumentation {
QueryMethodAdvice.class.getName());
}
- public static class QueryMethodAdvice {
+ public static class QueryMethodAdvice extends V4Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionFactoryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionFactoryInstrumentation.java
@@ -49,7 +49,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
SessionFactoryAdvice.class.getName());
}
- public static class SessionFactoryAdvice {
+ public static class SessionFactoryAdvice extends V4Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return final SharedSessionContract session) {

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionInstrumentation.java
@@ -102,7 +102,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
return transformers;
}
- public static class SessionCloseAdvice {
+ public static class SessionCloseAdvice extends V4Advice {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void closeSession(
@@ -126,7 +126,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class SessionMethodAdvice {
+ public static class SessionMethodAdvice extends V4Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startMethod(
@@ -152,7 +152,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetQueryAdvice {
+ public static class GetQueryAdvice extends V4Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getQuery(
@@ -168,7 +168,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetTransactionAdvice {
+ public static class GetTransactionAdvice extends V4Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getTransaction(
@@ -185,7 +185,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
}
}
- public static class GetCriteriaAdvice {
+ public static class GetCriteriaAdvice extends V4Advice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getCriteria(

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/TransactionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/TransactionInstrumentation.java
@@ -41,7 +41,7 @@ public class TransactionInstrumentation extends AbstractHibernateInstrumentation
TransactionCommitAdvice.class.getName());
}
- public static class TransactionCommitAdvice {
+ public static class TransactionCommitAdvice extends V4Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SessionState startCommit(@Advice.This final Transaction transaction) {

Support muzzle testInverse = true