Avoid creating context provider for intrumentations that do not need that
This should reduce number of allocations
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
@@ -5,6 +5,7 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
import datadog.trace.agent.tooling.context.FieldBackedProvider;
import datadog.trace.agent.tooling.context.InstrumentationContextProvider;
+import datadog.trace.agent.tooling.context.NoopContextProvider;
import datadog.trace.agent.tooling.muzzle.Reference;
import datadog.trace.agent.tooling.muzzle.ReferenceMatcher;
import datadog.trace.api.Config;
@@ -53,7 +54,11 @@ public interface Instrumenter {
instrumentationPrimaryName = instrumentationName;
enabled = Config.get().isIntegrationEnabled(instrumentationNames, defaultEnabled());
+ if (contextStore().size() > 0) {
contextProvider = new FieldBackedProvider(this);
+ } else {
+ contextProvider = NoopContextProvider.INSTANCE;
+ }
}
@Override

ADD
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/context/NoopContextProvider.java
+package datadog.trace.agent.tooling.context;
+
+import net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable;
+
+public class NoopContextProvider implements InstrumentationContextProvider {
+
+ public static NoopContextProvider INSTANCE = new NoopContextProvider();
+
+ private NoopContextProvider() {}
+
+ @Override
+ public Extendable instrumentationTransformer(final Extendable builder) {
+ return builder;
+ }
+
+ @Override
+ public Extendable additionalInstrumentation(final Extendable builder) {
+ return builder;
+ }
+}

Avoid creating context provider for intrumentations that do not need that

This should reduce number of allocations