Skip to content
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

Allow transforming classes with missing field types #8393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.opentelemetry.javaagent.tooling.asyncannotationsupport.WeakRefAsyncOperationEndStrategies;
import io.opentelemetry.javaagent.tooling.bootstrap.BootstrapPackagesBuilderImpl;
import io.opentelemetry.javaagent.tooling.bootstrap.BootstrapPackagesConfigurer;
import io.opentelemetry.javaagent.tooling.bytebuddy.SafeTypeStrategy;
import io.opentelemetry.javaagent.tooling.config.AgentConfig;
import io.opentelemetry.javaagent.tooling.config.ConfigPropertiesBridge;
import io.opentelemetry.javaagent.tooling.config.EarlyInitAgentConfig;
Expand Down Expand Up @@ -59,6 +58,8 @@
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.VisibilityBridgeStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.dynamic.scaffold.MethodGraph;
import net.bytebuddy.utility.JavaModule;

Expand Down Expand Up @@ -131,11 +132,12 @@ private static void installBytebuddyAgent(
new AgentBuilder.Default(
// default method graph compiler inspects the class hierarchy, we don't need it, so
// we use a simpler and faster strategy instead
new ByteBuddy().with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE))
new ByteBuddy()
.with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE)
.with(VisibilityBridgeStrategy.Default.NEVER)
.with(InstrumentedType.Factory.Default.FROZEN))
.with(AgentBuilder.TypeStrategy.Default.DECORATE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DECORATE javadocs say that:

A decoration does not allow for any standard transformations but can be used as a performance optimization compared to a redefinition, especially when implementing a Java agent that only applies ASM-based code changes.

I'm not sure what "standard transformations" mean in this context; do you know if this has any extra limitations compared to the previous strategy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same question, but the tests pass so it seems that it is working for our use case. I think that the advices that we use are only a small and very restrictive part of byte buddy transformations. It is possible that there is a difference when more complicated transforms are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference I noticed was the issue in #8391 where there was a failure instrumenting a static method with an advice that used this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the tests pass

👍

.disableClassFormatChanges()
// disableClassFormatChanges sets type strategy to TypeStrategy.Default.REDEFINE_FROZEN
// we'll wrap it with our own strategy
.with(new SafeTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE_FROZEN))
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(new RedefinitionDiscoveryStrategy())
.with(AgentBuilder.DescriptionStrategy.Default.POOL_ONLY)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ static void setUp() {
AgentBuilder builder =
new AgentBuilder.Default(
new ByteBuddy().with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE))
.with(AgentBuilder.TypeStrategy.Default.DECORATE)
.disableClassFormatChanges()
.with(new SafeTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE_FROZEN))
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(
new AgentBuilder.Listener.Adapter() {
Expand Down Expand Up @@ -92,8 +92,10 @@ void hasNoErrors() {
}

// com.google.common.base.Joiner is missing from runtime class path
@SuppressWarnings({"UnusedMethod", "MethodCanBeStatic"})
@SuppressWarnings({"UnusedMethod", "UnusedVariable", "MethodCanBeStatic"})
private static class SomeClass {
public Joiner joiner;

public static boolean isInstrumented() {
return false;
}
Expand Down