Mark our generated classes and members as synthetic (#3928)
This commit is contained in:
parent
a923efc077
commit
1dae415ebc
|
@ -39,6 +39,7 @@ import net.bytebuddy.asm.AsmVisitorWrapper;
|
|||
import net.bytebuddy.description.field.FieldDescription;
|
||||
import net.bytebuddy.description.field.FieldList;
|
||||
import net.bytebuddy.description.method.MethodList;
|
||||
import net.bytebuddy.description.modifier.SyntheticState;
|
||||
import net.bytebuddy.description.modifier.TypeManifestation;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -528,7 +529,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
if (!foundField) {
|
||||
cv.visitField(
|
||||
// Field should be transient to avoid being serialized with the object.
|
||||
Opcodes.ACC_PRIVATE | Opcodes.ACC_TRANSIENT,
|
||||
Opcodes.ACC_PRIVATE | Opcodes.ACC_TRANSIENT | Opcodes.ACC_SYNTHETIC,
|
||||
fieldName,
|
||||
contextType.getDescriptor(),
|
||||
null,
|
||||
|
@ -576,7 +577,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
|
||||
private MethodVisitor getAccessorMethodVisitor(String methodName) {
|
||||
return cv.visitMethod(
|
||||
Opcodes.ACC_PUBLIC,
|
||||
Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC,
|
||||
methodName,
|
||||
Utils.getMethodDefinition(interfaceType, methodName).getDescriptor(),
|
||||
null,
|
||||
|
@ -622,7 +623,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
String keyClassName, String contextClassName) {
|
||||
return byteBuddy
|
||||
.rebase(ContextStoreImplementationTemplate.class)
|
||||
.modifiers(Visibility.PUBLIC, TypeManifestation.FINAL)
|
||||
.modifiers(Visibility.PUBLIC, TypeManifestation.FINAL, SyntheticState.SYNTHETIC)
|
||||
.name(getContextStoreImplementationClassName(keyClassName, contextClassName))
|
||||
.visit(getContextStoreImplementationVisitor(keyClassName, contextClassName))
|
||||
.make();
|
||||
|
@ -992,6 +993,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
TypeDescription contextType = new TypeDescription.ForLoadedType(Object.class);
|
||||
return byteBuddy
|
||||
.makeInterface()
|
||||
.merge(SyntheticState.SYNTHETIC)
|
||||
.name(getContextAccessorInterfaceName(keyClassName, contextClassName))
|
||||
.defineMethod(getContextGetterName(keyClassName), contextType, Visibility.PUBLIC)
|
||||
.withoutCode()
|
||||
|
|
|
@ -27,7 +27,9 @@ tasks {
|
|||
val testFieldInjectionDisabled by registering(Test::class) {
|
||||
filter {
|
||||
includeTestsMatching("context.FieldInjectionDisabledTest")
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
include("**/FieldInjectionDisabledTest.*")
|
||||
jvmArgs("-Dotel.javaagent.experimental.field-injection.enabled=false")
|
||||
}
|
||||
|
||||
|
@ -35,6 +37,7 @@ tasks {
|
|||
dependsOn(testFieldInjectionDisabled)
|
||||
filter {
|
||||
excludeTestsMatching("context.FieldInjectionDisabledTest")
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
// this is needed for AgentInstrumentationSpecificationTest
|
||||
jvmArgs("-Dotel.javaagent.exclude-classes=config.exclude.packagename.*,config.exclude.SomeClass,config.exclude.SomeClass\$NestedClass")
|
||||
|
|
|
@ -42,10 +42,12 @@ class FieldBackedProviderTest extends AgentInstrumentationSpecification {
|
|||
boolean hasField = false
|
||||
boolean isPrivate = false
|
||||
boolean isTransient = false
|
||||
boolean isSynthetic = false
|
||||
for (Field field : keyClass.getDeclaredFields()) {
|
||||
if (field.getName().startsWith("__opentelemetry")) {
|
||||
isPrivate = Modifier.isPrivate(field.getModifiers())
|
||||
isTransient = Modifier.isTransient(field.getModifiers())
|
||||
isSynthetic = field.isSynthetic()
|
||||
hasField = true
|
||||
break
|
||||
}
|
||||
|
@ -53,12 +55,14 @@ class FieldBackedProviderTest extends AgentInstrumentationSpecification {
|
|||
|
||||
boolean hasMarkerInterface = false
|
||||
boolean hasAccessorInterface = false
|
||||
boolean accessorInterfaceIsSynthetic = false
|
||||
for (Class inter : keyClass.getInterfaces()) {
|
||||
if (inter.getName() == 'io.opentelemetry.javaagent.bootstrap.FieldBackedContextStoreAppliedMarker') {
|
||||
hasMarkerInterface = true
|
||||
}
|
||||
if (inter.getName().startsWith('io.opentelemetry.javaagent.bootstrap.instrumentation.context.FieldBackedProvider$ContextAccessor')) {
|
||||
hasAccessorInterface = true
|
||||
accessorInterfaceIsSynthetic = inter.isSynthetic()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +70,10 @@ class FieldBackedProviderTest extends AgentInstrumentationSpecification {
|
|||
hasField == shouldModifyStructure
|
||||
isPrivate == shouldModifyStructure
|
||||
isTransient == shouldModifyStructure
|
||||
isSynthetic == shouldModifyStructure
|
||||
hasMarkerInterface == shouldModifyStructure
|
||||
hasAccessorInterface == shouldModifyStructure
|
||||
accessorInterfaceIsSynthetic == shouldModifyStructure
|
||||
keyClass.newInstance().isInstrumented() == shouldModifyStructure
|
||||
|
||||
where:
|
||||
|
|
Loading…
Reference in New Issue