use of com.newrelic.agent.instrumentation.tracing.TraceDetailsBuilder in project newrelic-java-agent by newrelic.
the class AgentPreprocessors method gatherTraceInfo.
/**
* Visit the methods of weave classes which have {@link Trace} annotations. <br/>
* Methods which have tracers will be stored in the tracedWeaveInstrumentationDetails map.
*/
ClassVisitor gatherTraceInfo(ClassVisitor cv) {
// weave package name -> WeaverTraceDetails
Set<TracedWeaveInstrumentationTracker> initial = Sets.newConcurrentHashSet();
tracedWeaveInstrumentationDetails.putIfAbsent(weavePackageName, initial);
return new ClassVisitor(WeaveUtils.ASM_API_LEVEL, cv) {
private boolean isWeave = false;
private boolean isWeaveWithAnnotation = false;
private String originalName;
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
originalName = name;
super.visit(version, access, name, signature, superName, interfaces);
}
/**
* Get the name of the original class specified in @Weave(originalName="...")
*/
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
AnnotationVisitor av = super.visitAnnotation(desc, visible);
if (Type.getDescriptor(Weave.class).equals(desc)) {
isWeave = true;
return new AnnotationVisitor(WeaveUtils.ASM_API_LEVEL, av) {
@Override
public void visit(String name, Object value) {
if (name.equals("originalName")) {
originalName = ((String) value).replace('.', '/');
}
super.visit(name, value);
}
};
}
if (Type.getDescriptor(WeaveWithAnnotation.class).equals(desc)) {
isWeaveWithAnnotation = true;
}
return av;
}
@Override
public MethodVisitor visitMethod(final int access, final String methodName, final String methodDesc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, methodName, methodDesc, signature, exceptions);
return new MethodVisitor(WeaveUtils.ASM_API_LEVEL, mv) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
AnnotationVisitor av = super.visitAnnotation(desc, visible);
if (Type.getDescriptor(Trace.class).equals(desc)) {
Agent.LOG.log(Level.FINER, "Storing TracedWeaveInstrumentation: {0} - {1}.{2}({3})", weavePackageName, originalName, methodName, methodDesc);
TraceDetailsBuilder builder = TraceDetailsBuilder.newBuilder().setInstrumentationType(InstrumentationType.TracedWeaveInstrumentation).setInstrumentationSourceName(weavePackageName);
av = new Annotation(av, desc, builder) {
@Override
public void visitEnd() {
tracedWeaveInstrumentationDetails.get(weavePackageName).add(new TracedWeaveInstrumentationTracker(weavePackageName, originalName, new Method(methodName, methodDesc), isWeaveWithAnnotation, getTraceDetails(false)));
super.visitEnd();
}
};
}
return av;
}
};
}
};
}
Aggregations