-
Notifications
You must be signed in to change notification settings - Fork 881
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
Next steps to making the invokedynamic instrumentation approach the default #13031
Comments
Do I understand correctly that you wish to do this before the next major release? If so, you may need to raise this at the SIG meeting for discussion. I'm afraid that introducing this change in the stable version, even if it can be opted out, to field test and fix bugs does not align with our stability goals.
Some of the new experimental APIs are rarely needed so even if we don't manage to make them stable it should not be a problem.
I don't like this API either.
The problem is that current inline advice code is generally more readable than than the non-inline advice. It is possible that advice code may need to be changed during conversion by introducing helper classes etc. to keep the same level of readability. I'm not sure whether automated conversion can help with this. |
@laurit I've changed the issue description based on your remarks and the discussion in yesterdays SIG meeting. Let me know if anything is missing or you disagree with any points.
The main concern here is when multiple
I'm not intending to have the automatic conversion as a fire and forget tool. Rather that you run the tool, review and potentially adjust the results and then open a PR. It is intended to save us from the repetitive manual and therefore easily error prone tasks of applying the same rewrite patterns over and over again. |
We want to make the invokedynamic-based instrumentation approach the default one eventually.
This issue is intended to document the next steps towards this goal.
Per discussion in the SIG-Meeting, we'll do the following things first before switching the default of
otel.javaagent.experimental.indy
fromfalse
totrue
:VirtualField
s work efficiently in indy-modeVirtualField.find
calls from static initializers of helpers and advice classesVirtualField.find
in advice classes with static fields in helpersAfter that is done, we should be able to default
otel.javaagent.experimental.indy
totrue
. Based on our confidence in the feature, we'll have to decide whether to do this in a minor or major release.Inline advice will still be technically supported by overriding that config option back to
false
. This leaves us an escape hatch in case we find bugs without impacting users much (they can immediately switch back tofalse
to avoid the bugs).Then, in a later major version we'll remove support for inlined-advice and then can start gaining the benefits, such as removing shading.
In addition, we should clean up the APIs added to
ExperimentalInstrumentationModule
(see the API feature to (not) promote sections below). This is however not considered a blocker for defaultingotel.javaagent.experimental.indy
totrue
.Advice source code migration
For instrumentations to work with indy, the advice code needs to be written slightly differently, as described in the guide. This is currently done automatically for most advices at runtime via a runtime transformation of the advice bytecode. This of course is not ideal from a maintenance perspective, as the source-code doesn't match what is actually executed.
I'd suggest to do the following:
boolean requiresAdviceRewritingForIndy()
toExperimentalInstrumentationModule
and only apply the runtime-transformation accordinglyinlined = true
(which is the default): All other changes are backwards compatible and allow us to still run withotel.javaagent.experimental.indy=false
inlined = false
, which is an easy, IDE-supported change (e.g. IntelliJ structural replace feature)@Advice.AssignReturned
) based on javaparser a tool for AST-based, structural code modification with a lexically preserving printer (e.g. original comments and whitespace are preserved)AdviceTransformer
for instrumentations shipped with the agent. For external instrumentations, we can keep it around for some grace period and print a warning (e.g.Please migrate your advices, here is a link to our guide
).API features to promote
With the completion #11457, we'll have all our instrumentation capable of working with invokedynamic. We need to make sure to also have a clean plugin interface with indy-support when making it the default for external instrumentations. Currently, those features live in the
ExperimentalInstrumentationModule
class.We'll need to clean up and migrate the relevant features to
InstrumentationModule
:In order to make the
ClassInjector
insteadThe following two features I'm not sure about whether we want to actually have them in the public API or whether we'll keep them for internal modules only:
API features not to promote
getModuleGroup
getModuleGroup(): This feature was added to ease the conversion of some instrumentations which are tightly coupled by accessing classes from each other directly. A cleaner approach for this requirement is to have:
This would involve a very big refactor for our existing instrumentations, but I don't feel like this is the case for external instrumentations. Therefore I think it would be better in terms of "best-practices" to not have this method part of the public API to promote the correct way of doing things. Maybe we could rewrite one of the internal modules (after inlining is not supported anymore) to showcase how to do this.
agentPackagesToHide
agentPackagesToHide(): This method is used when trying to instrument classes which are also present in the agent-classloader: The problem is that for linking, classes found in the agent classloader take precedence over classes from the instrumented classloader. This means that if the classes are present in both, the instrumentation won't be able to actually use/instrument them. I feel like this is an esoteric edge which should not be exposed to the public api in order to keep it simpler, as it should be very rare to stumble across.
An example where this is needed internally is the instrumentation of the opentelemetry-api: The instrumentation needs to bridge application opentelemetry-APIs, while at the same timing bringing it's own opentelemetry-API version (eventually unshaded).
The text was updated successfully, but these errors were encountered: