-
Notifications
You must be signed in to change notification settings - Fork 362
Fix instrumentation being dropped when a JDK AOT cache is used #12506
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78d6577
Retry retransformation without the TaskWrapper interface
gibKim 8736e87
Align the listener with the IAST one and cover it with a test
gibKim 205064e
Log once at info when queueing time profiling is disabled
gibKim d1be92e
Say task unwrapping, not queueing time, in the log and javadoc
gibKim d0c90c8
Say task unwrapping in the retry debug log too
gibKim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...adog/trace/agent/tooling/bytebuddy/profiling/TaskWrapperRedefinitionStrategyListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package datadog.trace.agent.tooling.bytebuddy.profiling; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.annotation.Nonnull; | ||
| import net.bytebuddy.agent.builder.AgentBuilder; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * {@link UnwrappingVisitor} redefines the structure of a class by adding an interface, meaning that | ||
| * it cannot be applied to already loaded classes. | ||
| * | ||
| * <p>This listener will disable the visitor to prevent a failure with the whole redefinition batch. | ||
| */ | ||
| public final class TaskWrapperRedefinitionStrategyListener | ||
| extends AgentBuilder.RedefinitionStrategy.Listener.Adapter { | ||
|
|
||
| private static final Logger LOGGER = | ||
| LoggerFactory.getLogger(TaskWrapperRedefinitionStrategyListener.class); | ||
| private static final boolean DEBUG = LOGGER.isDebugEnabled(); | ||
|
|
||
| public static final TaskWrapperRedefinitionStrategyListener INSTANCE = | ||
| new TaskWrapperRedefinitionStrategyListener(); | ||
|
|
||
| private TaskWrapperRedefinitionStrategyListener() {} | ||
|
|
||
| @Override | ||
| @Nonnull | ||
| public Iterable<? extends List<Class<?>>> onError( | ||
| final int index, | ||
| @Nonnull final List<Class<?>> batch, | ||
| @Nonnull final Throwable throwable, | ||
| @Nonnull final List<Class<?>> types) { | ||
| if (UnwrappingVisitor.ENABLED) { | ||
| // logged once: the flag is one-way, so this branch cannot be re-entered | ||
| LOGGER.info( | ||
| "Disabling task unwrapping for queueing time profiling: retransformation failed for a" | ||
| + " batch of {} classes because adding the TaskWrapper interface is a structural" | ||
| + " change the JVM rejects for already loaded classes (e.g. materialized from a" | ||
| + " JDK 24+ AOT cache). Retrying the batch without it. Queueing time is still" | ||
| + " recorded, but the task type is reported as the wrapper class. All other" | ||
| + " instrumentation is preserved.", | ||
| batch.size()); | ||
| UnwrappingVisitor.ENABLED = false; | ||
| return Collections.singletonList(batch); | ||
| } else { | ||
| if (DEBUG) { | ||
| LOGGER.debug( | ||
| "Exception while retransforming after disabling the visitor in batch {}, task unwrapping is disabled", | ||
| index); | ||
| } | ||
| return Collections.emptyList(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onComplete( | ||
| final int amount, final List<Class<?>> types, final Map<List<Class<?>>, Throwable> failures) { | ||
| if (DEBUG) { | ||
| if (!UnwrappingVisitor.ENABLED) { | ||
| LOGGER.debug("Retransforming succeeded with a disabled visitor"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When IAST is enabled on a JDK 24+ AOT-cache launch, this branch installs only
TaintableRedefinitionStrategyListener, so the new recovery path never runs. The first failed batch disablesTaintableVisitorand is retried, butUnwrappingVisitor.ENABLEDremains true; the retry therefore makes the same prohibitedTaskWrapperinterface change, after which the IAST listener returns no further batches and all instrumentation is still dropped. Use a combined listener (or teach the IAST listener to disable both structural visitors) so this configuration also recovers.Useful? React with 👍 / 👎.