1

I wanted to instrument a large number of classes to use with Spring Insight and instead of adding the @InsightOperation manually to the methods, I wrote an aspect to annotate the methods using point cuts.

However, this is not working. While the manual annotation affects the Spring Insight trace logging, the AspectJ method does not work.

Is there anything I am doing wrong here? (I decompiled the classes after aspectizing and do find the annotation in the class methods)

This is the aspect code snippet:

declare @method :public * com.example.IExample.execute(..) : @InsightOperation;

Vishal
  • 381
  • 3
  • 10
  • *(I decompiled the classes after aspectizing and do find the annotation in the class methods* Do I understand correctly: the annotations are present in the class files, but it still doesn't work? – Sean Patrick Floyd May 18 '11 at 15:36
  • Could it be that load time weaving (which is what Spring Insight uses) ignores or is unable to detect the annotation added by the compile time aspect? – Vishal May 18 '11 at 18:07

3 Answers3

0

An easy work around is to call another method from within your aspect method to continue executing the join point. I only tried calling a static method in a static class. See below my code for adding the @InsightOperation to all my JSON serialization.

My aspect:

@Aspect
public class JSONSerializerAspect {

@Around("call(* *.JSONSerializer.serialize(..)) && args(target)")
public Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable {
      return JSONSerializationWrapper.serialize(joinPoint, target);
    }
}

The static class it is calling:

public class JSONSerializationWrapper {

    @InsightOperation(label = "JSON_SERIALIZATION")
    public static Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable {
        return joinPoint.proceed(new Object[]{target});
    }

}

I'm using this myself and tested that it works.

lammert
  • 1,456
  • 14
  • 20
0

Spring documentation says this:

Use of the @Insight* annotations are optional. They make it easy for end users to define custom operation frames and end points without needing to create a plug-in. Because end user code modification is required to use the annotations, they are an option for users who cannot or do not wish to write aspects.

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html

So looks like the only way is to write a custom plugin

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html#tutorial-plugin

Vishal
  • 381
  • 3
  • 10
0

It is possible that the Insight LTW does not pick up your introduced annotations. I'll have to dig deeper on that.

In the meantime, you can try a more low-level annotation:

   com.springsource.insight.collection.method.MethodOperationsCollected

If you look at the spring-core plugin, you will see that it does something similar:

  public aspect RepositoryMethodOperationCollectionAspect {
      declare @type: @Repository * : @MethodOperationsCollected;
  }
Jon Travis
  • 303
  • 2
  • 8