Refactor classes of log injection services to improve readability
MODIFY
dd-java-agent/instrumentation/log4j1/log4j1.gradle
dd-java-agent/instrumentation/log4j1/log4j1.gradle
@@ -13,8 +13,8 @@ muzzle {
}
configurations {
- // In order to test the real log4j library we need to remove the log4j transitive dependency
- // dependency brought in by :dd-java-agent:testing over 'log4j-over-slf4j' which would shadow
+ // In order to test the real log4j library we need to remove the log4j transitive
+ // dependency 'log4j-over-slf4j' brought in by :dd-java-agent:testing which would shadow
// the log4j module under test using a proxy to slf4j instead.
testCompile.exclude group: 'org.slf4j', module: 'log4j-over-slf4j'

MODIFY
dd-java-agent/instrumentation/log4j1/src/main/java/datadog/trace/instrumentation/log4j1/Log4j1MDCInstrumentation.java
dd-java-agent/instrumentation/log4j1/src/main/java/datadog/trace/instrumentation/log4j1/Log4j1MDCInstrumentation.java
@@ -9,8 +9,10 @@ import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.log.LogContextScopeListener;
import datadog.trace.api.Config;
import datadog.trace.api.GlobalTracer;
+
import java.lang.reflect.Method;
import java.util.Map;
+
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
@@ -47,16 +49,18 @@ public class Log4j1MDCInstrumentation extends Instrumenter.Default {
public static class MDCContextAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void mdcClassInitialized(@Advice.This Object instance) {
- try {
if (instance == null) {
return;
}
+ try {
Class<?> mdcClass = instance.getClass();
final Method putMethod = mdcClass.getMethod("put", String.class, Object.class);
final Method removeMethod = mdcClass.getMethod("remove", String.class);
GlobalTracer.get().addScopeListener(new LogContextScopeListener(putMethod, removeMethod));
} catch (final NoSuchMethodException e) {
+ org.slf4j.LoggerFactory.getLogger(instance.getClass())
+ .debug("Failed to add log4j ThreadContext span listener", e);
}
}
}

MODIFY
dd-java-agent/instrumentation/log4j1/src/test/groovy/Log4j1MDCTest.groovy
dd-java-agent/instrumentation/log4j1/src/test/groovy/Log4j1MDCTest.groovy
-import datadog.trace.agent.test.log.injection.LogContextContextInjectionTest
+import datadog.trace.agent.test.log.injection.LogContextInjectionTest
import org.apache.log4j.MDC
-class Log4j1MDCTest extends LogContextContextInjectionTest {
+class Log4j1MDCTest extends LogContextInjectionTest {
@Override
def put(String key, Object value) {

MODIFY
dd-java-agent/instrumentation/log4j2/log4j2.gradle
dd-java-agent/instrumentation/log4j2/log4j2.gradle
@@ -5,8 +5,8 @@ ext {
}
configurations {
- // In order to test the real log4j library we need to remove the log4j transitive dependency
- // dependency brought in by :dd-java-agent:testing over 'log4j-over-slf4j' which would shadow
+ // In order to test the real log4j library we need to remove the log4j transitive
+ // dependency 'log4j-over-slf4j' brought in by :dd-java-agent:testing which would shadow
// the log4j module under test using a proxy to slf4j instead.
testCompile.exclude group: 'org.slf4j', module: 'log4j-over-slf4j'
}

MODIFY
dd-java-agent/instrumentation/log4j2/src/test/groovy/Log4jThreadContextTest.groovy
dd-java-agent/instrumentation/log4j2/src/test/groovy/Log4jThreadContextTest.groovy
-import datadog.trace.agent.test.log.injection.LogContextContextInjectionTest
+import datadog.trace.agent.test.log.injection.LogContextInjectionTest
import org.apache.logging.log4j.ThreadContext
-class Log4jThreadContextTest extends LogContextContextInjectionTest {
+class Log4jThreadContextTest extends LogContextInjectionTest {
@Override
def put(String key, Object value) {

MODIFY
dd-java-agent/instrumentation/slf4j-mdc/src/test/groovy/Slf4jMDCTest.groovy
dd-java-agent/instrumentation/slf4j-mdc/src/test/groovy/Slf4jMDCTest.groovy
-import datadog.trace.agent.test.log.injection.LogContextContextInjectionTest
+import datadog.trace.agent.test.log.injection.LogContextInjectionTest
import org.slf4j.MDC
-class Slf4jMDCTest extends LogContextContextInjectionTest {
+class Slf4jMDCTest extends LogContextInjectionTest {
@Override
def put(String key, Object value) {

RENAME
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/log/injection/LogContextContextInjectionTest.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/log/injection/LogContextInjectionTest.groovy
@@ -9,9 +9,10 @@ import io.opentracing.util.GlobalTracer
import java.util.concurrent.atomic.AtomicReference
/**
- * This class represents the standard test cases that new logging library integration MUST satisfy in order to support log injection.
+ * This class represents the standard test cases that new logging library integrations MUST
+ * satisfy in order to support log injection.
*/
-abstract class LogContextContextInjectionTest extends AgentTestRunner {
+abstract class LogContextInjectionTest extends AgentTestRunner {
/**
* Set in the framework-specific context the given value at the given key
@@ -19,7 +20,7 @@ abstract class LogContextContextInjectionTest extends AgentTestRunner {
abstract put(String key, Object value)
/**
- * Get from the framework-specific context the given value at the given key
+ * Get from the framework-specific context the value at the given key
*/
abstract get(String key)

Refactor classes of log injection services to improve readability