-
Notifications
You must be signed in to change notification settings - Fork 623
Description
Add an 'IgnoreTraceComponent' annotation to liberty trace injection.
See pull request #33610
That is to remove build errors relating to non-static trace components.
For example:
WARNING: TraceComponent field declared but must be static in class: com.ibm.wsspi.persistence.internal.eclipselink.LogChannel
ERROR: Instrumentation failed for com/ibm/wsspi/persistence/internal/eclipselink/LogChannel. Please see previous messages
WARNING: TraceComponent field declared but must be static in class: com.ibm.ws.security.oauth20.error.impl.BrowserAndServerLogMessage
ERROR: Instrumentation failed for com/ibm/ws/security/oauth20/error/impl/BrowserAndServerLogMessage. Please see previous messages
These errors occur when running liberty trace instruementation on a class which contains a non-static trace component field.
For example:
TraceComponent tc = Tr.register(GraphQLAuthorizationExtension.class);
Per our current liberty trace injection, any "TraceComponent" field which is not static causes a build error:
open-liberty/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/
LibertyTracePreprocessInstrumentation.java
private void processLibertyTraceComponentDiscovery(ClassTraceInfo info) { // Line 263
List<FieldNode> traceComponentFields = getFieldsByDesc(LIBERTY_TRACE_COMPONENT_TYPE.getDescriptor(), info.classNode.fields);
if (!traceComponentFields.isEmpty()) {
// Remove references to non-static TraceComponents
for (int i = traceComponentFields.size() - 1; i >= 0; i--) {
FieldNode fn = traceComponentFields.get(i);
if ((fn.access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) {
// Trace Component fields found, but not static
traceComponentFields.remove(i);
StringBuilder sb = new StringBuilder();
sb.append("WARNING: TraceComponent field declared but must be static in class: ");
sb.append(info.classNode.name.replaceAll("/", "\\."));
info.warnings.add(sb.toString());
info.failInstrumentation = true;
}
}
The proposal is to add a new field annotation, "IgnoreTraceComponent" which could be used to ignore cases where a non-static trace component must be used and should not cause a build error.
The LIBERTY_TRACE_COMPONENT_TYPE is defined here:
open-liberty/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/bci/
LibertyTracingClassAdapter.java
public final static Type TR_TYPE = Type.getObjectType("com/ibm/websphere/ras/Tr");
public final static Type TRACE_COMPONENT_TYPE = Type.getObjectType("com/ibm/websphere/ras/TraceComponent");
open-liberty/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/
LibertyTracePreprocessInstrumentation.java
public final static Type LIBERTY_TR_TYPE = LibertyTracingClassAdapter.TR_TYPE;
public final static Type LIBERTY_TRACE_COMPONENT_TYPE = LibertyTracingClassAdapter.TRACE_COMPONENT_TYPE;
The new annotation would be processed by a new method visitor, which would register, either in the class information, or in field information, when a field is marked as "IgnoreTraceComponent". This would be checked by LibertyTracePreprocessInstrumentation and would prevent the warning and errors from being displayed.
open-liberty/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/introspect/
TraceConfigClassVisitor.java
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
FieldVisitor fv = super.visitField(access, name, desc, signature, value);
if ((access & Opcodes.ACC_STATIC) != 0) {
FieldInfo fieldInfo = new FieldInfo(name, desc);
classInfo.addFieldInfo(fieldInfo);
}
return fv;
}