-
Notifications
You must be signed in to change notification settings - Fork 875
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
Add auto configuration for spring scheduling instrumentation using aop #12438
Conversation
unproxiedTesterSimpleClassName = unproxiedTester.getClass().getSimpleName(); | ||
unproxiedTesterClassName = unproxiedTester.getClass().getName(); | ||
|
||
AspectJProxyFactory factory = new AspectJProxyFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you trying to enable the AspectJ support with Spring? In this case, you could use @EnableAspectJAutoProxy
(https://docs.spring.io/spring-framework/reference/core/aop/ataspectj/aspectj-support.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these codes are purposed for unit tests to test the functions of SpringSchedulingInstrumentationAspect
. If we use @EnableAspectJAutoProxy
annotation, we must start the AnnotationConfigApplicationContext
which is too heavy for tests since we only need to test the function of Aop I think. Using AspectJProxyFactory
to create proxy instance and let it parse and apply the SpringSchedulingInstrumentationAspect
will also meet our demands for tests.
dc6ca08
to
77d7cd0
Compare
@ConditionalOnEnabledInstrumentation(module = "spring-scheduling") | ||
@ConditionalOnClass({Scheduled.class, Aspect.class}) | ||
@Configuration | ||
public class SpringSchedulingInstrumentationAutoConfiguration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class SpringSchedulingInstrumentationAutoConfiguration { | |
class SpringSchedulingInstrumentationAutoConfiguration { |
@NonNull Context parentContext, | ||
@NonNull REQUEST classAndMethod) { | ||
attributes | ||
.put(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the same thing done with the Java agent instrumentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The final result is quite the same as java agent, but it's implemented differently. Java agent uses AddThreadDetailsSpanProcessor
to add thread.id
to the attributes of a span, while in spring boot auto configuration this information seems missing in span. Hence, to match the final span as java agent I write this.
For further extension, this class may be extracted as a common span processor and configured automatically just like the one in java agent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanations. The current implementation is good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For further extension, this class may be extracted as a common span processor and configured automatically just like the one in java agent?
I think this is a good idea 👍
I'd recommend removing it from this PR (since in the current state it's currently inconsistent with the other spring starter instrumentation), then we can merge, and then you can send a follow-up PR for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds cool to me😊. I've made the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me.
Thanks @kyy1996!
77d7cd0
to
27aba3b
Compare
27aba3b
to
8da1085
Compare
Since library instrumentation for spring scheduling is missing. I would like to provide a simple library instrumentation using AOP for spring scheduling.
Using this approach, we could intercept calls of any
@Scheduled
annotated method and start spans for them. Though this can cover most of the use cases, there's a limitation that tasks registered throughScheduledTaskRegistrar#addCronTask
programmatically will not be recorded since they don't have@Scheduled
annotation.Also, I've added an auto configuration for it, so that this can be an out-of-box instrumentation.
Properties for this instrumentation such as
otel.instrumentation.spring-scheduling.experimental-span-attributes
andotel.instrumentation.spring-scheduling.enabled
are aligned with spring scheduling javaagent instrumentation.