Enable instrumenting old java bytecode
ADD
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/DDTransformers.java
+package datadog.trace.agent.tooling;
+
+import net.bytebuddy.agent.builder.AgentBuilder;
+import net.bytebuddy.asm.TypeConstantAdjustment;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.dynamic.DynamicType;
+import net.bytebuddy.utility.JavaModule;
+
+public class DDTransformers {
+
+ private static final AgentBuilder.Transformer CONSTANT_ADJUSTER =
+ new AgentBuilder.Transformer() {
+ @Override
+ public DynamicType.Builder<?> transform(
+ DynamicType.Builder<?> builder,
+ TypeDescription typeDescription,
+ ClassLoader classLoader,
+ JavaModule javaModule) {
+ return builder.visit(TypeConstantAdjustment.INSTANCE);
+ }
+ };
+
+ public static AgentBuilder.Transformer defaultTransformers() {
+ return CONSTANT_ADJUSTER;
+ }
+}

ADD
dd-java-agent/testing/src/test/groovy/InstrumentOldBytecode.groovy
+import com.ibm.as400.resource.ResourceLevel
+import datadog.trace.agent.test.AgentTestRunner
+
+class InstrumentOldBytecode extends AgentTestRunner {
+ def "can instrument old bytecode"() {
+ expect:
+ new ResourceLevel().toString() == "instrumented"
+ }
+}

ADD
dd-java-agent/testing/src/test/java/IBMResourceLevelInstrumentation.java
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+import com.google.auto.service.AutoService;
+import datadog.trace.agent.tooling.DDAdvice;
+import datadog.trace.agent.tooling.DDTransformers;
+import datadog.trace.agent.tooling.Instrumenter;
+import net.bytebuddy.agent.builder.AgentBuilder;
+import net.bytebuddy.asm.Advice;
+
+@AutoService(Instrumenter.class)
+public class IBMResourceLevelInstrumentation extends Instrumenter.Configurable {
+ public IBMResourceLevelInstrumentation() {
+ super(IBMResourceLevelInstrumentation.class.getName());
+ }
+
+ @Override
+ protected AgentBuilder apply(AgentBuilder agentBuilder) {
+ return agentBuilder
+ .type(named("com.ibm.as400.resource.ResourceLevel"))
+ .transform(DDTransformers.defaultTransformers())
+ .transform(DDAdvice.create().advice(named("toString"), ToStringAdvice.class.getName()))
+ .asDecorator();
+ }
+
+ public static class ToStringAdvice {
+ @Advice.OnMethodExit(suppress = Throwable.class)
+ static void toStringReplace(@Advice.Return(readOnly = false) String ret) {
+ ret = "instrumented";
+ }
+ }
+}

MODIFY
dd-java-agent/testing/testing.gradle
dd-java-agent/testing/testing.gradle
@@ -10,4 +10,7 @@ dependencies {
compile project(':dd-trace-ot')
compile project(':dd-java-agent:agent-tooling')
+
+ // test instrumenting java 1.1 bytecode
+ testCompile group: 'net.sf.jt400', name: 'jt400', version: '6.1'
}

Enable instrumenting old java bytecode