Skip to content

Commit 37ad948

Browse files
committed
Move postProcessor option to InstrumenterModule, so it can be shared across the grouped instrumentations
1 parent bacc8ca commit 37ad948

File tree

9 files changed

+15
-35
lines changed

9 files changed

+15
-35
lines changed

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/CombiningTransformerBuilder.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.namedOneOf;
1010
import static net.bytebuddy.matcher.ElementMatchers.not;
1111

12-
import datadog.trace.agent.tooling.Instrumenter.WithPostProcessor;
1312
import datadog.trace.agent.tooling.bytebuddy.ExceptionHandlers;
1413
import datadog.trace.agent.tooling.context.FieldBackedContextInjector;
1514
import datadog.trace.agent.tooling.context.FieldBackedContextMatcher;
@@ -73,17 +72,12 @@ public final class CombiningTransformerBuilder
7372
private Map<String, String> contextStore;
7473
private AgentBuilder.Transformer contextRequestRewriter;
7574
private HelperTransformer helperTransformer;
75+
private Advice.PostProcessor.Factory postProcessor;
7676
private MuzzleCheck muzzle;
7777

7878
// temporary buffer for collecting advice; reset for each instrumenter
7979
private final List<AgentBuilder.Transformer> advice = new ArrayList<>();
8080

81-
/**
82-
* Post processor to be applied to instrumenter advices if they implement {@link
83-
* WithPostProcessor}
84-
*/
85-
private Advice.PostProcessor.Factory postProcessor;
86-
8781
public CombiningTransformerBuilder(
8882
AgentBuilder agentBuilder, InstrumenterIndex instrumenterIndex) {
8983
this.agentBuilder = agentBuilder;
@@ -134,6 +128,8 @@ private void prepareInstrumentation(InstrumenterModule module, int instrumentati
134128
module.useAgentCodeSource(), module.getClass().getSimpleName(), helperClassNames)
135129
: null;
136130

131+
postProcessor = module.postProcessor();
132+
137133
muzzle = new MuzzleCheck(module, instrumentationId);
138134
}
139135

@@ -208,9 +204,6 @@ private void buildTypeMatcher(Instrumenter member, int transformationId) {
208204

209205
private void buildTypeAdvice(Instrumenter member, int transformationId) {
210206

211-
postProcessor =
212-
member instanceof WithPostProcessor ? ((WithPostProcessor) member).postProcessor() : null;
213-
214207
if (null != helperTransformer) {
215208
advice.add(helperTransformer);
216209
}

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.security.ProtectionDomain;
77
import java.util.Collection;
8-
import net.bytebuddy.asm.Advice;
98
import net.bytebuddy.asm.AsmVisitorWrapper;
109
import net.bytebuddy.description.method.MethodDescription;
1110
import net.bytebuddy.description.type.TypeDescription;
@@ -82,11 +81,6 @@ interface WithTypeStructure {
8281
ElementMatcher<TypeDescription> structureMatcher();
8382
}
8483

85-
/** Instrumentation that wants to apply additional structure checks after type matching. */
86-
interface WithPostProcessor {
87-
Advice.PostProcessor.Factory postProcessor();
88-
}
89-
9084
/** Instrumentation that provides advice which affects the whole type. */
9185
interface HasTypeAdvice extends Instrumenter {
9286
/**

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/InstrumenterModule.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ public ElementMatcher<? super MethodDescription> methodIgnoreMatcher() {
156156
return isSynthetic();
157157
}
158158

159+
/** Override this to post-process the operand stack of any transformed methods. */
160+
public Advice.PostProcessor.Factory postProcessor() {
161+
return null;
162+
}
163+
159164
/**
160165
* Context stores to define for this instrumentation. Are added to matching class loaders.
161166
*
@@ -235,7 +240,7 @@ public boolean isApplicable(Set<TargetSystem> enabledSystems) {
235240

236241
/** Parent class for all IAST related instrumentations */
237242
@SuppressForbidden
238-
public abstract static class Iast extends InstrumenterModule implements WithPostProcessor {
243+
public abstract static class Iast extends InstrumenterModule {
239244
public Iast(String instrumentationName, String... additionalNames) {
240245
super(instrumentationName, additionalNames);
241246
}

dd-java-agent/instrumentation/spring-webmvc-3.1/src/main/java/datadog/trace/instrumentation/springweb/TemplateAndMatrixVariablesInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
/** Obtain template and matrix variables for RequestMappingInfoHandlerMapping. */
3737
@AutoService(InstrumenterModule.class)
3838
public class TemplateAndMatrixVariablesInstrumentation extends InstrumenterModule
39-
implements Instrumenter.ForSingleType,
40-
Instrumenter.HasMethodAdvice,
41-
Instrumenter.WithPostProcessor {
39+
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
4240

4341
private Advice.PostProcessor.Factory postProcessorFactory;
4442

dd-java-agent/instrumentation/spring-webmvc-3.1/src/main/java/datadog/trace/instrumentation/springweb/TemplateVariablesUrlHandlerInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
/** Obtain template and matrix variables for AbstractUrlHandlerMapping */
3636
@AutoService(InstrumenterModule.class)
3737
public class TemplateVariablesUrlHandlerInstrumentation extends InstrumenterModule
38-
implements Instrumenter.ForSingleType,
39-
Instrumenter.HasMethodAdvice,
40-
Instrumenter.WithPostProcessor {
38+
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
4139

4240
private Advice.PostProcessor.Factory postProcessorFactory;
4341

dd-java-agent/instrumentation/spring-webmvc-6.0/src/main/java/datadog/trace/instrumentation/springweb6/TemplateAndMatrixVariablesInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
/** Obtain template and matrix variables for RequestMappingInfoHandlerMapping. */
1919
@AutoService(InstrumenterModule.class)
2020
public class TemplateAndMatrixVariablesInstrumentation extends InstrumenterModule
21-
implements Instrumenter.ForSingleType,
22-
Instrumenter.HasMethodAdvice,
23-
Instrumenter.WithPostProcessor {
21+
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
2422

2523
private Advice.PostProcessor.Factory postProcessorFactory;
2624

dd-java-agent/instrumentation/spring-webmvc-6.0/src/main/java/datadog/trace/instrumentation/springweb6/TemplateVariablesUrlHandlerInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
/** Obtain template and matrix variables for AbstractUrlHandlerMapping */
1919
@AutoService(InstrumenterModule.class)
2020
public class TemplateVariablesUrlHandlerInstrumentation extends InstrumenterModule
21-
implements Instrumenter.ForSingleType,
22-
Instrumenter.HasMethodAdvice,
23-
Instrumenter.WithPostProcessor {
21+
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
2422

2523
private Advice.PostProcessor.Factory postProcessorFactory;
2624

dd-java-agent/instrumentation/vertx-web-3.4/src/main/java/datadog/trace/instrumentation/vertx_3_4/server/RouteImplInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
@AutoService(InstrumenterModule.class)
2020
public class RouteImplInstrumentation extends InstrumenterModule
21-
implements Instrumenter.ForKnownTypes,
22-
Instrumenter.HasMethodAdvice,
23-
Instrumenter.WithPostProcessor {
21+
implements Instrumenter.ForKnownTypes, Instrumenter.HasMethodAdvice {
2422

2523
private Advice.PostProcessor.Factory postProcessorFactory;
2624

dd-java-agent/instrumentation/vertx-web-4.0/src/main/java/datadog/trace/instrumentation/vertx_4_0/server/RouteImplInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
@AutoService(InstrumenterModule.class)
1818
public class RouteImplInstrumentation extends InstrumenterModule
19-
implements Instrumenter.ForKnownTypes,
20-
Instrumenter.HasMethodAdvice,
21-
Instrumenter.WithPostProcessor {
19+
implements Instrumenter.ForKnownTypes, Instrumenter.HasMethodAdvice {
2220

2321
private Advice.PostProcessor.Factory postProcessorFactory;
2422

0 commit comments

Comments
 (0)