diff --git a/dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy b/dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy index 674c9fb18e..883be47b35 100644 --- a/dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy +++ b/dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy @@ -13,7 +13,6 @@ class TraceAnnotationsTest extends AgentTestRunner { ConfigUtils.updateConfig { System.clearProperty("dd.trace.annotations") } - refreshTestTracer() } def "test simple case annotations"() { diff --git a/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java b/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java index 2153bbe962..e83ee600fb 100644 --- a/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java +++ b/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java @@ -64,12 +64,12 @@ public abstract class AgentTestRunner extends Specification { * *
Before the start of each test the reported traces will be reset.
*/
- public static ListWriter TEST_WRITER;
+ public static final ListWriter TEST_WRITER;
// having a reference to io.opentracing.Tracer in test field
// loads opentracing before bootstrap classpath is setup
// so we declare tracer as an object and cast when needed.
- protected static Object TEST_TRACER;
+ protected static final Object TEST_TRACER;
protected static final SetpreserveRuntimeId = false
to copy the previous runtimeId
- * to the new config instance.
+ * Reset the global configuration. Please note that Runtime ID is preserved to the pre-existing value.
*/
- static void resetConfig(preserveRuntimeId = true) {
+ static void resetConfig() {
// Ensure the class was re-transformed properly in AgentTestRunner.makeConfigInstanceModifiable()
assert Modifier.isPublic(ConfigInstance.FIELD.getModifiers())
assert Modifier.isStatic(ConfigInstance.FIELD.getModifiers())
@@ -75,22 +73,29 @@ class ConfigUtils {
def previousConfig = ConfigInstance.FIELD.get(null)
def newConfig = new Config()
ConfigInstance.FIELD.set(null, newConfig)
- if (previousConfig != null && preserveRuntimeId) {
+ if (previousConfig != null) {
ConfigInstance.RUNTIME_ID_FIELD.set(newConfig, ConfigInstance.RUNTIME_ID_FIELD.get(previousConfig))
}
}
+ // Keep track of config instance already made modifiable
+ private static isConfigInstanceModifiable = false
+
static void makeConfigInstanceModifiable() {
+ if (isConfigInstanceModifiable) {
+ return
+ }
+
def instrumentation = ByteBuddyAgent.install()
final transformer =
new AgentBuilder.Default()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.RedefinitionStrategy.Listener.ErrorEscalating.FAIL_FAST)
- // Config is injected into the bootstrap, so we need to provide a locator.
+ // Config is injected into the bootstrap, so we need to provide a locator.
.with(
new AgentBuilder.LocationStrategy.Simple(
ClassFileLocator.ForClassLoader.ofSystemLoader()))
- .ignore(none()) // Allow transforming boostrap classes
+ .ignore(none()) // Allow transforming bootstrap classes
.type(named("datadog.trace.api.Config"))
.transform { builder, typeDescription, classLoader, module ->
builder
@@ -104,6 +109,7 @@ class ConfigUtils {
.transform(Transformer.ForField.withModifiers(PUBLIC, VOLATILE))
}
.installOn(instrumentation)
+ isConfigInstanceModifiable = true
final field = ConfigInstance.FIELD
assert Modifier.isPublic(field.getModifiers())