New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile-time weaving support for TimedAspect #1149
Comments
Have you added aspectj weaving to the build section of your POM?
|
Yes. The aspectj-maven-plugin configuration I posted in my initial post is under |
My current hypothesis is that the |
Also, one way to work around this is to write your own aspect that weaves around an annotation and use the |
I don't have much expertise on AspectJ but after some quick research, it seems to require a similar configuration to |
Looks like spring-aspects.jar compiles with ajc, then. I think the solution to this ticket is to either compile Micrometer with ajc, or improve the documentation on how to get Micrometer to work properly with AspectJ. I can write a small addition to the documentation explaining this, if desired. |
I am running into the exact same issue as @jefftap. While the compile time weaving seems to succeed, at runtime the aspectOf methods are not there on the
Would be great to have some documentation on how to get this working. |
Methods annotated with @timed now use Micrometers annotation. The @Gauge annotation has been remove without replacement for now. While configuration for the use of Micrometer's TimedAspect has been prepared, it is not yet active because of compatibility issues with compile-time weaving. See micrometer-metrics/micrometer#1149.
I didn't manage to get this working with CTW. As far as I understood it, it seems that micrometer-core is not compiled with the ajc and thus the aspects are missing the required factory methods. |
The issue still persist. As noted higher it could be resolved by using LTW, but in my case it is not an option because I do not have access to the deployment setup, and the only option is CTW which doesn't work with this library |
Same issue here, CTW does not work. Is there any plan to support it properly, so CTW will work ? |
I've had the same issue with CTW, although I got around this by wrapping the aspect like this for now.
and adding the following to the aop.xml
It would be great if this works out of the box for CTW. |
Hi, for those on the interweb who came here for load time weaving (LTW), I confirm that it works. <aspectj>
<weaver>
<include within="io.micrometer.core..*"/>
<include within="my.app..*"/>
</weaver>
<aspects>
<aspect name="io.micrometer.core.aop.TimedAspect"/>
</aspects>
</aspectj> To be used in conjunction with a class like: package my.app;
public class App {
@Timed("xyz")
public void fun1() { }
} In a Spring Boot application with the I'm a newbie when it comes to aspects, but I'm wondering what the advantages of CTW over LTW are. |
Because I often answer questions on StackOverflow, I found this issue, not for the first time in the last few years. Today I took some time to look into it, producing a little example project, showing how to apply https://github.com/kriegaex/SO_AJ_MicrometerTimed_67803726 The project simply consists of one class and a POM + an explanatory read-me file. The gist of it is: You must make sure to apply binary weaving to the Micrometer aspect in order to transform it into a real AspectJ aspect, and then apply that aspect to your own project. |
Since there are ways of how to achieve this is there anything else we should do here, other than maybe document this? |
My workaround is very contrived. IMO, it is unreasonable to assume that any normal user who does not happen to be an AspectJ expert can find out how to do this. Even if it was documented, users would be doing the Micrometer team's work there.
Yes, add an Aspectj compilation step to the Gradle build (e.g. using Freefair plugin) and make sure that what is advertised as an AspectJ aspect, ... micrometer/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java Lines 36 to 37 in 2252347
... does actually really deserve its name, and avoid that incomplete non-AspectJ compilation with Javac needs to be finished by the user. That this happens to work with LTW, because the AspectJ weaver is smart enough to notice and finish the job, does not mean that CTW is some kind of second-class citizen. Make your product easy to use. The correctly compiled aspect would, of course, still work with LTW. With CTW, the library could just be put on the aspectpath, as is customary. No extra build steps or extra modules, creating a refined version of this library as an input for later steps. Of course, micrometer/micrometer-core/build.gradle Lines 80 to 81 in 2252347
which is a superset of |
Hi, I am attempting to make use of
TimedAspect
via AspectJ compile-time weaving using theaspectj-maven-plugin
. When the aspect code is executed, it throws one of the two errors, depending on what is being executed:This usually indicates that the AspectJ weaver has not properly processed the aspect code. I am not sure if this is a problem with my own code/configuration, or if it's an issue in Micrometer's jar. The aspect works perfectly fine using Spring AOP, but I would prefer to use AspectJ weaving with
@Timed
to allow it access to private/protected methods and the other various benefits one gets from AspectJ integration.Relevant information:
aspectj-maven-plugin configuration:
The text was updated successfully, but these errors were encountered: