-
Notifications
You must be signed in to change notification settings - Fork 130
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
[maven-extension] Propagate OTel context to plugin mojos #786
[maven-extension] Propagate OTel context to plugin mojos #786
Conversation
…s and span attributes
@@ -45,6 +47,8 @@ public final class OtelExecutionListener extends AbstractExecutionListener { | |||
|
|||
private static final Logger logger = LoggerFactory.getLogger(OtelExecutionListener.class); | |||
|
|||
private static final ThreadLocal<Scope> MOJO_EXECUTION_SCOPE = new ThreadLocal<>(); |
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.
Does this cause any issue with parallel Maven builds with -T
?
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, using a threadlocal from ExecutionListener#mojoStarted()
to ExecutionListener#mojoSucceeded()
/ ExecutionListener#mojoFailed()
works even when parallelising the Maven builds with -T
.
The code contains state checks to ensure this assumption continues to be valid with newer versions of Maven parallelization.
I tested with 8 cores and -T 1C
on a Macbok Air m2 2022 building https://github.com/apache/maven. I could confirm looking at the debug logs that the build was massively parallelised and that the threadlocal worked as desired.
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.
I just added a comment in the code to explain the rationale.
Works for me. Thanks a lot @cyrille-leclerc ! |
Description:
Propagate OTel context to plugin mojos so they can add their own attributes and spans to traces.
Existing Issue(s):
None
Testing:
No unit test framework compatible with JUnit 5 for Maven builds yet.
Documentation:
See updated README.md
Outstanding items:
None