Review changes.
This commit is contained in:
parent
26a0194b84
commit
a73b8c36f0
|
@ -70,14 +70,15 @@ import net.bytebuddy.utility.JavaModule;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class FieldBackedProvider implements InstrumentationContextProvider {
|
public class FieldBackedProvider implements InstrumentationContextProvider {
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Note: the value here has to be inside on of the prefixes in
|
* Note: the value here has to be inside on of the prefixes in
|
||||||
datadog.trace.agent.tooling.Utils#BOOTSTRAP_PACKAGE_PREFIXES. This ensures that 'isolating' (or 'module')
|
* datadog.trace.agent.tooling.Utils#BOOTSTRAP_PACKAGE_PREFIXES. This ensures that 'isolating' (or
|
||||||
classloaders like jboss and osgi see injected classes. This works because we instrument those classloaders
|
* 'module') classloaders like jboss and osgi see injected classes. This works because we
|
||||||
to load everything inside bootstrap packages.
|
* instrument those classloaders to load everything inside bootstrap packages.
|
||||||
*/
|
*/
|
||||||
private static final String DYNAMIC_CLASSES_PACKAGE =
|
private static final String DYNAMIC_CLASSES_PACKAGE =
|
||||||
"datadog.trace.bootstrap.instrumentation.context.";
|
"datadog.trace.bootstrap.instrumentation.context.";
|
||||||
|
|
||||||
private static final String INJECTED_FIELDS_MARKER_CLASS_NAME =
|
private static final String INJECTED_FIELDS_MARKER_CLASS_NAME =
|
||||||
Utils.getInternalName(FieldBackedContextStoreAppliedMarker.class.getName());
|
Utils.getInternalName(FieldBackedContextStoreAppliedMarker.class.getName());
|
||||||
|
|
||||||
|
@ -118,24 +119,24 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
||||||
public AgentBuilder.Identified.Extendable instrumentationTransformer(
|
public AgentBuilder.Identified.Extendable instrumentationTransformer(
|
||||||
AgentBuilder.Identified.Extendable builder) {
|
AgentBuilder.Identified.Extendable builder) {
|
||||||
if (instrumenter.contextStore().size() > 0) {
|
if (instrumenter.contextStore().size() > 0) {
|
||||||
/*
|
/**
|
||||||
Install transformer that rewrites accesses to context store with specialized bytecode that invokes appropriate
|
* Install transformer that rewrites accesses to context store with specialized bytecode that
|
||||||
storage implementation.
|
* invokes appropriate storage implementation.
|
||||||
*/
|
*/
|
||||||
builder =
|
builder =
|
||||||
builder.transform(getTransformerForASMVisitor(getContextStoreReadsRewritingVisitor()));
|
builder.transform(getTransformerForASMVisitor(getContextStoreReadsRewritingVisitor()));
|
||||||
|
|
||||||
/*
|
/**
|
||||||
We inject into bootstrap classloader because field accessor interfaces are needed by
|
* We inject into bootstrap classloader because field accessor interfaces are needed by
|
||||||
context store implementations. Unfortunately this forces us to remove stored type checking
|
* context store implementations. Unfortunately this forces us to remove stored type checking
|
||||||
because actual classes may not be available at this point.
|
* because actual classes may not be available at this point.
|
||||||
*/
|
*/
|
||||||
builder = builder.transform(bootstrapHelperInjector(fieldAccessorInterfaces.values()));
|
builder = builder.transform(bootstrapHelperInjector(fieldAccessorInterfaces.values()));
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* We inject context store implementation into bootstrap classloader because same implementation
|
* We inject context store implementation into bootstrap classloader because same
|
||||||
* may be used by different instrumentations and it has to use same static map in case of
|
* implementation may be used by different instrumentations and it has to use same static map
|
||||||
* fallback to map-backed storage.
|
* in case of fallback to map-backed storage.
|
||||||
*/
|
*/
|
||||||
builder = builder.transform(bootstrapHelperInjector(contextStoreImplementations.values()));
|
builder = builder.transform(bootstrapHelperInjector(contextStoreImplementations.values()));
|
||||||
}
|
}
|
||||||
|
@ -333,9 +334,9 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
||||||
|
|
||||||
if (fieldInjectionEnabled) {
|
if (fieldInjectionEnabled) {
|
||||||
for (final Map.Entry<String, String> entry : instrumenter.contextStore().entrySet()) {
|
for (final Map.Entry<String, String> entry : instrumenter.contextStore().entrySet()) {
|
||||||
/*
|
/**
|
||||||
For each context store defined in a current instrumentation we create an agent builder
|
* For each context store defined in a current instrumentation we create an agent builder
|
||||||
that injects necessary fields.
|
* that injects necessary fields.
|
||||||
*/
|
*/
|
||||||
builder =
|
builder =
|
||||||
builder
|
builder
|
||||||
|
@ -343,6 +344,12 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
||||||
safeHasSuperType(named(entry.getKey())).and(not(isInterface())),
|
safeHasSuperType(named(entry.getKey())).and(not(isInterface())),
|
||||||
instrumenter.classLoaderMatcher())
|
instrumenter.classLoaderMatcher())
|
||||||
.and(safeToInjectFieldsMatcher())
|
.and(safeToInjectFieldsMatcher())
|
||||||
|
/**
|
||||||
|
* By adding the muzzleMatcher here, we are adding risk that the rules for injecting
|
||||||
|
* the classes into the classloader and the rules for adding the field to the class
|
||||||
|
* might be different. However the consequences are much greater if the class is not
|
||||||
|
* injected but the field is added, since that results in a NoClassDef error.
|
||||||
|
*/
|
||||||
.and(muzzleMatcher)
|
.and(muzzleMatcher)
|
||||||
.transform(
|
.transform(
|
||||||
getTransformerForASMVisitor(
|
getTransformerForASMVisitor(
|
||||||
|
@ -361,12 +368,13 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
||||||
final JavaModule module,
|
final JavaModule module,
|
||||||
final Class<?> classBeingRedefined,
|
final Class<?> classBeingRedefined,
|
||||||
final ProtectionDomain protectionDomain) {
|
final ProtectionDomain protectionDomain) {
|
||||||
/*
|
/**
|
||||||
The idea here is that we can add fields if class is just being loaded (classBeingRedefined == null)
|
* The idea here is that we can add fields if class is just being loaded
|
||||||
and we have to add same fields again if class we added fields before is being transformed again.
|
* (classBeingRedefined == null) and we have to add same fields again if class we added
|
||||||
Note: here we assume that Class#getInterfaces() returns list of interfaces defined immediately on a
|
* fields before is being transformed again. Note: here we assume that Class#getInterfaces()
|
||||||
given class, not inherited from its parents. It looks like current JVM implementation does exactly
|
* returns list of interfaces defined immediately on a given class, not inherited from its
|
||||||
this but javadoc is not explicit about that.
|
* parents. It looks like current JVM implementation does exactly this but javadoc is not
|
||||||
|
* explicit about that.
|
||||||
*/
|
*/
|
||||||
return classBeingRedefined == null
|
return classBeingRedefined == null
|
||||||
|| Arrays.asList(classBeingRedefined.getInterfaces())
|
|| Arrays.asList(classBeingRedefined.getInterfaces())
|
||||||
|
|
|
@ -44,6 +44,7 @@ dependencies {
|
||||||
|
|
||||||
testCompile project(':dd-java-agent:testing')
|
testCompile project(':dd-java-agent:testing')
|
||||||
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
||||||
|
// Added to ensure cross compatibility:
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.0')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.0')
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.3')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.3')
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ dependencies {
|
||||||
|
|
||||||
testCompile project(':dd-java-agent:testing')
|
testCompile project(':dd-java-agent:testing')
|
||||||
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
||||||
|
// Added to ensure cross compatibility:
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-3.3')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-3.3')
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.3')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.3')
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,17 @@ dependencies {
|
||||||
|
|
||||||
testCompile project(':dd-java-agent:testing')
|
testCompile project(':dd-java-agent:testing')
|
||||||
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
testCompile project(':dd-java-agent:instrumentation:jdbc')
|
||||||
|
// Added to ensure cross compatibility:
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-3.3')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-3.3')
|
||||||
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.0')
|
testCompile project(':dd-java-agent:instrumentation:hibernate:core-4.0')
|
||||||
|
|
||||||
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '4.3.0.Final'
|
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '4.3.0.Final'
|
||||||
|
testCompile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.0.Final'
|
||||||
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
|
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
|
||||||
|
testCompile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.5.1.RELEASE'
|
||||||
|
|
||||||
latestDepTestCompile group: 'org.hibernate', name: 'hibernate-core', version: '+'
|
latestDepTestCompile group: 'org.hibernate', name: 'hibernate-core', version: '+'
|
||||||
|
latestDepTestCompile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '+'
|
||||||
latestDepTestCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
|
latestDepTestCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'
|
||||||
|
latestDepTestCompile group: 'org.springframework.data', name: 'spring-data-jpa', version: '+'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue