-
Notifications
You must be signed in to change notification settings - Fork 324
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
Support for setting the application class loader when starting a transaction via the public api #2369
Support for setting the application class loader when starting a transaction via the public api #2369
Conversation
…a transaction via the public api
👋 @tobiasstadler Thanks a lot for your contribution! It may take some time before we review a PR, so even if you don’t see activity for some time, it does not mean that we have forgotten about it. Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming milestone. The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it. |
❕ Build Aborted
Expand to view the summary
Build stats
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
Thanks for the proposed fix @tobiasstadler ! ❤️ While this solves your problem and it worths considering, it can only work when the plugin class knows the application class loader, so maybe it's not a very generic solution. In addition, it extends the API in a way that raises the proficiency bar and our aim is to keep it as simple as possible. The general problem is that we use an incorrect CL, as explained in #2350 . |
Thank you for your feedback! Yes, this is by no means a generic solution. But I think I still need this, even if a generic solution for #2350 is available. As I said neither the class loader of the instrumented class nor the context class loader at that time have access to the the log4j classes. So in my opinion the |
Sorry, I didn't see anywhere above that you mentioned that the context CL doesn't have access to the MDC. Did you try to set the CL to The general concept of MDC (or You report this doesn't work when used in an external plugins, as opposed to internal plugin. Assuming that your internal plugin instrumentation would have been the same, what would you set there as "initiating Class Loader" if you instrumented the same class as an internal plugin? |
I don‘t think it will work if my plugin was an internal plugin, because the context class loader is the ejb module class loader (which does not have access the the application/logging classes) when I start/activate the transaction. So the MdcActivationListener shouldn‘t be able to find my logging class. But I think I could set the context class loader to my application class loader (with access to the logging classes) before starting/activating the transaction and restore the old class loader after the activation. So if the generic solution falls back to the context class loader it could also work for me. |
I changed my plugin to change the context class loader before starting/activating the transaction, set the |
I implemented "try the application class loader AND fallback to the cortex class loader" in #2374 (works for me) |
I want to provide a wholistic fix for this external plugins CL issue, so I would be grateful if you provide some more concrete details:
|
@eyalkoren The problematic plugin is: https://github.com/tobiasstadler/apm-wildfly-remote-ejb-plugin. The integration test is close enough to our actual production use case. Regarding you questions:
|
e.g. in Context Class Loader ( Application Class Loader ( |
I see, the JBoss module system. So with regards to:
I believe you can use multiple versions for a module, is that correct? If so, multiple class loaders may load versions of the class that your plugin is instrumenting. Either way, this addresses my general consideration - the usefulness of setting the library class loader for this purpose is doubtful. Another solution would be to use a
|
Let me think about it for a bit and see if and how it is related to the fix we need to do anyway (we shouldn't set an agent CL as described in #2350 ). |
Shouldn‘t setting the „correct“ class loader (by the external plugin) as context class loader before activating the transaction also work, when the logging plugin falls back to context class loader? It requires the external plugin to set/unset the context class loader, but it is easy to implement in the agent. I think that my problem is an edge case and in most cases the context class loader will be the „correct“ one, so most external plugins probably won‘t need to do anything. |
I am, fine with changing the context class loader in my plugin. |
Sorry, I wasn't really clear on that- I definitely think we should fallback to looking in the context CL not only when the "initiating CL" is not set, but also when it is set and fails to load the MDC class, so I assume we want #2374 anyway (that's what I proposed above). |
#2350 is not really an issue for me as I will deploy a workaround to make log correlation work for me. So no need to hurry (at least for my issue). |
@eyalkoren #2376 works for me. Thanks You! |
…pplication-class-loader
@eyalkoren Did you already get a chance to think about this change? |
Likely to be superseded by #2412 |
While #2412 may solve the MDC issue, the mechanism to overwrite the service name will still not work, because the transaction is associated with no/the wrong class loader. In my case the transaction will have |
@felixbarny @eyalkoren While #2412 solves the log correlation case, but overwriting the service name still doesn't work (in my case). Could we please adapt the public api as proposed in this PR. |
Adding a class loader argument to There can be issues when setting the class loader after spans have already created. The consequence is that some spans may have the wrong service name and version. I think that risk is acceptable. We can document that the method should be called before creating child spans. |
@felixbarny Thank You for your review. I will come up with an implementation in the next days |
@felixbarny I implemented you suggestion in #2444 |
#2444 is the way to go |
What does this PR do?
Adds support for setting the application class lower when starting a transaction via the public api (e.g. external plugins).
My external plugin instruments a class which is not loaded by the class loader of my application and does not have access to application classes (but it does know what the correct class loader is). For external plugins the initiating class loader of a transaction is a
IndyPluginClassLoader
with the class loader of the instrumented class as its parent. So when theMdcActivationListener
tries to lookup the logging implementations it cannot find any, as they are not part of the class loader of the instrumented class.By specifying the initiating class loader (the one with the application and logging classes) when starting a transaction the log correlation is then able to find the used logging implementation.
Checklist