Add more logs to debug
MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/AnnotationsTracingAgent.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/AnnotationsTracingAgent.java
@@ -18,22 +18,24 @@ package com.datadoghq.trace.agent;
import io.opentracing.contrib.agent.OpenTracingAgent;
import java.lang.instrument.Instrumentation;
+import lombok.extern.slf4j.Slf4j;
/**
* This class provides a wrapper around the ByteMan agent, to establish required system properties
* and the manager class.
*/
+@Slf4j
public class AnnotationsTracingAgent extends OpenTracingAgent {
- public static void premain(String agentArgs, Instrumentation inst) throws Exception {
+ public static void premain(String agentArgs, final Instrumentation inst) throws Exception {
agentArgs = addManager(agentArgs);
-
+ log.debug("Using premain for loading {}", AnnotationsTracingAgent.class.getSimpleName());
org.jboss.byteman.agent.Main.premain(agentArgs, inst);
}
- public static void agentmain(String agentArgs, Instrumentation inst) throws Exception {
+ public static void agentmain(String agentArgs, final Instrumentation inst) throws Exception {
agentArgs = addManager(agentArgs);
-
+ log.debug("Using agentmain for loading {}", AnnotationsTracingAgent.class.getSimpleName());
org.jboss.byteman.agent.Main.agentmain(agentArgs, inst);
}
@@ -44,7 +46,7 @@ public class AnnotationsTracingAgent extends OpenTracingAgent {
agentArgs += ",";
}
agentArgs += "manager:" + TraceAnnotationsManager.class.getName();
-
+ log.debug("Agent args=: {}", agentArgs);
return agentArgs;
}
}

MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/DDJavaAgentInfo.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/DDJavaAgentInfo.java
@@ -2,7 +2,9 @@ package com.datadoghq.trace.agent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import lombok.extern.slf4j.Slf4j;
+@Slf4j
public class DDJavaAgentInfo {
public static final String VERSION;
@@ -22,5 +24,6 @@ public class DDJavaAgentInfo {
v = "unknown";
}
VERSION = v;
+ log.debug("dd-java-agent - version: {}", v);
}
}

MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
@@ -18,11 +18,10 @@ import lombok.extern.slf4j.Slf4j;
public class InstrumentationChecker {
private static final String CONFIG_FILE = "dd-trace-supported-framework";
+ private static InstrumentationChecker INSTANCE;
private final Map<String, List<Map<String, String>>> rules;
private final Map<String, String> frameworks;
- private static InstrumentationChecker INSTANCE;
-
/* For testing purpose */
InstrumentationChecker(
final Map<String, List<Map<String, String>>> rules, final Map<String, String> frameworks) {
@@ -50,40 +49,6 @@ public class InstrumentationChecker {
return INSTANCE.doGetUnsupportedRules();
}
- private List<String> doGetUnsupportedRules() {
-
- final List<String> unsupportedRules = new ArrayList<>();
- for (final String rule : rules.keySet()) {
-
- // Check rules
- boolean supported = false;
- for (final Map<String, String> check : rules.get(rule)) {
- if (frameworks.containsKey(check.get("artifact"))) {
- final boolean matched =
- Pattern.matches(
- check.get("supported_version"), frameworks.get(check.get("artifact")));
- if (!matched) {
- log.debug(
- "Library conflict: supported_version={}, actual_version={}",
- check.get("supported_version"),
- frameworks.get(check.get("artifact")));
- supported = false;
- break;
- }
- supported = true;
- log.trace("Instrumentation rule={} is supported", rule);
- }
- }
-
- if (!supported) {
- log.info("Instrumentation rule={} is not supported", rule);
- unsupportedRules.add(rule);
- }
- }
-
- return unsupportedRules;
- }
-
private static Map<String, String> scanLoadedLibraries() {
final Map<String, String> frameworks = new HashMap<>();
@@ -104,6 +69,7 @@ public class InstrumentationChecker {
frameworks.put(artifactId, version);
}
}
+ log.debug("{} libraries found in the class-path", frameworks.size());
return frameworks;
}
@@ -116,6 +82,7 @@ public class InstrumentationChecker {
recurse(filesList, file);
} else {
if (file.getName().endsWith(".jar")) {
+ log.trace("{} found in the classpath", file.getName());
filesList.add(file);
}
}
@@ -140,4 +107,38 @@ public class InstrumentationChecker {
return null;
}
}
+
+ private List<String> doGetUnsupportedRules() {
+
+ final List<String> unsupportedRules = new ArrayList<>();
+ for (final String rule : rules.keySet()) {
+
+ // Check rules
+ boolean supported = false;
+ for (final Map<String, String> check : rules.get(rule)) {
+ if (frameworks.containsKey(check.get("artifact"))) {
+ final boolean matched =
+ Pattern.matches(
+ check.get("supported_version"), frameworks.get(check.get("artifact")));
+ if (!matched) {
+ log.debug(
+ "Library conflict: supported_version={}, actual_version={}",
+ check.get("supported_version"),
+ frameworks.get(check.get("artifact")));
+ supported = false;
+ break;
+ }
+ supported = true;
+ log.trace("Instrumentation rule={} is supported", rule);
+ }
+ }
+
+ if (!supported) {
+ log.info("Instrumentation rule={} is not supported", rule);
+ unsupportedRules.add(rule);
+ }
+ }
+
+ return unsupportedRules;
+ }
}

MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/TraceAnnotationsManager.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/TraceAnnotationsManager.java
@@ -11,7 +11,12 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javassist.ClassPool;
@@ -37,9 +42,20 @@ import org.reflections.util.FilterBuilder;
@Slf4j
public class TraceAnnotationsManager {
- private static Retransformer transformer;
-
private static final String AGENT_RULES = "otarules.btm";
+ private static final String CURRENT_SPAN_EXISTS = "IF TRUE\n";
+ private static final String BUILD_SPAN = "DO\n" + "getTracer().buildSpan(\"";
+ private static final String CLOSE_PARENTHESIS = "\")";
+ private static final String START = ".startActive();";
+ private static final String EXIT_RULE =
+ "IF getTracer().activeSpan() != null\n" + "DO\n" + "getTracer().activeSpan().deactivate();\n";
+ private static final String EXCEPTION_EXIT_RULE =
+ "BIND span:io.opentracing.ActiveSpan = getTracer().activeSpan()\n"
+ + "IF span != null\n"
+ + "DO\n"
+ + "span.setTag(io.opentracing.tag.Tags.ERROR.getKey(),\"true\");\n"
+ + "span.deactivate();\n";
+ private static Retransformer transformer;
/**
* This method initializes the manager.
@@ -47,6 +63,7 @@ public class TraceAnnotationsManager {
* @param trans The ByteMan retransformer
*/
public static void initialize(final Retransformer trans) throws Exception {
+ log.debug("Initializing {}", TraceAnnotationsManager.class.getSimpleName());
transformer = trans;
//Load configuration
final AgentTracerConfig agentTracerConfig =
@@ -55,6 +72,8 @@ public class TraceAnnotationsManager {
DDTracerFactory.CONFIG_PATH,
AgentTracerConfig.class);
+ log.debug("Configuration: {}", agentTracerConfig.toString());
+
final List<String> loadedScripts = loadRules(ClassLoader.getSystemClassLoader());
//Check if some rules have to be uninstalled
@@ -100,7 +119,7 @@ public class TraceAnnotationsManager {
try (PrintWriter pr = new PrintWriter(sw)) {
transformer.removeScripts(new ArrayList<>(rulesToRemove), pr);
}
- log.info(sw.toString());
+ log.info("Uninstall rule scripts: {}", rulesToRemove.toString());
}
}
@@ -140,6 +159,11 @@ public class TraceAnnotationsManager {
}
log.debug("OpenTracing Agent rules loaded");
+ if (log.isTraceEnabled()) {
+ for (final String rule : scripts) {
+ log.trace("Loading rule: {}", rule);
+ }
+ }
return scripts;
}
@@ -202,6 +226,7 @@ public class TraceAnnotationsManager {
log.warn(
"Could not create rule for method " + method + ". Proceed to next annoted method.", e);
}
+ log.trace("Instrumenting annotated method: {}", method.getName());
}
try {
final StringWriter sw = new StringWriter();
@@ -209,7 +234,7 @@ public class TraceAnnotationsManager {
transformer.installScript(
Arrays.asList(generatedScripts.toString()), Arrays.asList("@Trace annotations"), pr);
}
- log.debug(sw.toString());
+ log.trace("Install new rules: \n{}", sw.toString());
} catch (final Exception e) {
log.warn("Could not install annotation scripts.", e);
}
@@ -264,23 +289,6 @@ public class TraceAnnotationsManager {
scriptNames.add(uri.toString());
}
- private static final String CURRENT_SPAN_EXISTS = "IF TRUE\n";
-
- private static final String BUILD_SPAN = "DO\n" + "getTracer().buildSpan(\"";
- private static final String CLOSE_PARENTHESIS = "\")";
-
- private static final String START = ".startActive();";
-
- private static final String EXIT_RULE =
- "IF getTracer().activeSpan() != null\n" + "DO\n" + "getTracer().activeSpan().deactivate();\n";
-
- private static final String EXCEPTION_EXIT_RULE =
- "BIND span:io.opentracing.ActiveSpan = getTracer().activeSpan()\n"
- + "IF span != null\n"
- + "DO\n"
- + "span.setTag(io.opentracing.tag.Tags.ERROR.getKey(),\"true\");\n"
- + "span.deactivate();\n";
-
private static String buildSpan(final CtMethod javassistMethod) {
try {
final Trace trace = (Trace) javassistMethod.getAnnotation(Trace.class);

MODIFY
dd-trace-annotations/dd-trace-annotations.gradle
dd-trace-annotations/dd-trace-annotations.gradle
@@ -4,5 +4,6 @@ apply from: "${rootDir}/gradle/jacoco.gradle"
description = 'dd-trace-annotations'
dependencies {
+ compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testCompile group: 'junit', name: 'junit', version: '3.8.1'
}

MODIFY
dd-trace-annotations/src/main/java/com/datadoghq/trace/DDTraceAnnotationsInfo.java
dd-trace-annotations/src/main/java/com/datadoghq/trace/DDTraceAnnotationsInfo.java
@@ -2,7 +2,9 @@ package com.datadoghq.trace;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import lombok.extern.slf4j.Slf4j;
+@Slf4j
public class DDTraceAnnotationsInfo {
public static final String VERSION;
@@ -23,5 +25,6 @@ public class DDTraceAnnotationsInfo {
v = "unknown";
}
VERSION = v;
+ log.debug("dd-trace-annotations - version: {}", v);
}
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTraceInfo.java
dd-trace/src/main/java/com/datadoghq/trace/DDTraceInfo.java
@@ -2,7 +2,9 @@ package com.datadoghq.trace;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import lombok.extern.slf4j.Slf4j;
+@Slf4j
public class DDTraceInfo {
public static final String JAVA_VERSION = System.getProperty("java.version", "unknown");
@@ -26,5 +28,6 @@ public class DDTraceInfo {
v = "unknown";
}
VERSION = v;
+ log.debug("dd-trace - version: {}", v);
}
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -65,6 +65,11 @@ public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentrac
this.sampler = sampler;
registry = new CodecRegistry();
registry.register(Format.Builtin.HTTP_HEADERS, new HTTPCodec());
+ log.debug(
+ "New tracer instance, default-service={}, writer={}, sampler={}",
+ defaultServiceName,
+ writer.getClass().getSimpleName(),
+ sampler.getClass().getSimpleName());
}
/**

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerFactory.java
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerFactory.java
@@ -94,16 +94,20 @@ public class DDTracerFactory {
SYSTEM_PROPERTY_CONFIG_PATH, CONFIG_PATH, TracerConfig.class);
DDTracer tracer = null;
+ log.trace("Tracer configuration: \n{}", tracerConfig);
if (tracerConfig == null) {
log.info("No valid configuration file {} found. Loading default tracer.", CONFIG_PATH);
tracer = new DDTracer();
} else {
+ log.debug("Create a tracer instance from the configuration");
+
tracer = DDTracerFactory.create(tracerConfig);
}
//Create decorators from resource files
final List<AbstractDecorator> decorators = DDDecoratorsFactory.createFromResources();
for (final AbstractDecorator decorator : decorators) {
+ log.debug("Loading decorator: {}", decorator.getClass().getSimpleName());
tracer.addDecorator(decorator);
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerResolver.java
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerResolver.java
@@ -12,26 +12,28 @@ import lombok.extern.slf4j.Slf4j;
@AutoService(TracerResolver.class)
public class DDTracerResolver extends TracerResolver {
- @Override
- protected Tracer resolve() {
- log.info("Creating the Datadog tracer");
-
- //Find a resource file named dd-trace.yml
- DDTracer tracer = null;
- //Create tracer from resource files
- tracer = DDTracerFactory.createFromConfigurationFile();
-
- return tracer;
- }
-
public static Tracer registerTracer() {
final Tracer tracer = TracerResolver.resolveTracer();
if (tracer == null) {
+ log.warn("Cannot resolved the tracer, use NoopTracer");
return NoopTracerFactory.create();
}
+ log.info("Register the tracer via GlobalTracer");
GlobalTracer.register(tracer);
return tracer;
}
+
+ @Override
+ protected Tracer resolve() {
+ log.info("Creating the Datadog Tracer from the resolver");
+
+ //Find a resource file named dd-trace.yml
+ DDTracer tracer = null;
+ //Create tracer from resource files
+ tracer = DDTracerFactory.createFromConfigurationFile();
+
+ return tracer;
+ }
}

Add more logs to debug