Skip to content

Commit

Permalink
Also force dynamic typing in case of non-indy instrumentation, add ja…
Browse files Browse the repository at this point in the history
…vadoc
  • Loading branch information
JonasKunz committed Aug 13, 2024
1 parent 9516966 commit 6a6001b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.tooling.Utils;
import io.opentelemetry.javaagent.tooling.bytebuddy.ExceptionHandlers;
import io.opentelemetry.javaagent.tooling.instrumentation.indy.ForceDynamicallyTypedAssignReturnedFactory;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -21,7 +22,9 @@ final class TypeTransformerImpl implements TypeTransformer {
this.agentBuilder = agentBuilder;
adviceMapping =
Advice.withCustomMapping()
.with(new Advice.AssignReturned.Factory().withSuppressed(Throwable.class));
.with(
new ForceDynamicallyTypedAssignReturnedFactory(
new Advice.AssignReturned.Factory().withSuppressed(Throwable.class)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatchers;

/**
* This factory is designed to wrap around {@link Advice.PostProcessor.Factory} and ensures that
* {@link net.bytebuddy.implementation.bytecode.assign.Assigner.Typing#DYNAMIC} is used everywhere.
*
* <p>This helps by avoiding errors where the instrumented bytecode is suddenly unloadable due to
* incompatible assignments and preventing cluttering advice code annotations with the explicit
* typing.
*/
public class ForceDynamicallyTypedAssignReturnedFactory implements Advice.PostProcessor.Factory {

private static final String TO_ARGUMENTS_TYPENAME =
Expand Down

0 comments on commit 6a6001b

Please sign in to comment.