Merge pull request #1237 from DataDog/mar-kolya/do-not-create-field-profider-for-all-intrsumentations

Avoid creating context provider for intrumentations that do not need …
This commit is contained in:
Nikolay Martynov 2020-02-20 09:51:45 -05:00 committed by GitHub
commit 27cb2111b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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());
contextProvider = new FieldBackedProvider(this);
if (contextStore().size() > 0) {
contextProvider = new FieldBackedProvider(this);
} else {
contextProvider = NoopContextProvider.INSTANCE;
}
}
@Override

View File

@ -0,0 +1,20 @@
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;
}
}