I'm using micronaut tracing library to instrument an application. I want to use the tracing annotations (@NewSpan
and @ContinueSpan
) in classes that are not beans registered in the application context. I'm not getting spans for the methods in those classes, and I'm wondering if for the tracing annotations to work the classes need to be beans.
Asked
Active
Viewed 37 times
1

Miguel Ferreira
- 1,282
- 11
- 27
1 Answers
0
In order to have an effect when using @NewSpan
and @ContinueSpan
Micronaut requires Micronaut beans. Therefore the answer to your question is no, that does not work that way.
The reason is that for example @NewSpan
used Micronaut AOP. Micronaut AOP only works with Micronaut beans. For example the @NewSpan
annotation indicates that a call to a method annotated with @NewSpan
should be intercepted.

saw303
- 8,051
- 7
- 50
- 90
-
Thanks for the answer @saw303! Do you know of any way to setup tracing for non bean classes? – Miguel Ferreira Jun 27 '23 at 09:17
-
Can you provide an example? Main thing is, why don’t you let Micronaut create that Java class instance for you and then it’s all working as you expect it – saw303 Jun 27 '23 at 13:46
-
For example a domain model class, or a domain service. I tend to only wire classes in to the framework when needed, and keep them as POJOs as much as possible. I was thinking that maybe it would be possible to do the instrumentation manually, in such a way that it would all come together nicely. But I do get your point about the way it's done in the framework using AOP. – Miguel Ferreira Jul 04 '23 at 07:57
-
Alternatively you can write a BeanFactory that instanciates the POJO for you and the POJO itself remains untouched (no framework annotations) but it’s available as bean – saw303 Jul 04 '23 at 15:58