Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
e7204baa5a
|
@ -150,7 +150,7 @@ public void myMethod() throws InterruptedException{
|
|||
</dependency>
|
||||
```
|
||||
|
||||
- Enable custom tracing by adding this JVM property `-Ddd.enable_custom_tracing`
|
||||
- Enable custom tracing by adding in the `dd-trace.yaml` config file `enableCustomTracing: true`
|
||||
|
||||
If you want to see custom tracing in action please run the [Dropwizard example](https://github.com/DataDog/dd-trace-java/blob/dev/dd-trace-examples/dropwizard-mongo-client/).
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@
|
|||
</excludes>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>false</reuseForks>
|
||||
<argLine>-Xmx500m -Xms500m -XX:MaxPermSize=256m -Dorg.jboss.byteman.verbose=true -Djavaagent.enableAnnotations
|
||||
<argLine>-Xmx1g -Xms1g -XX:MaxPermSize=512m -Dorg.jboss.byteman.verbose=true
|
||||
-javaagent:${M2_REPO}/com/datadoghq/dd-java-agent/${project.version}/dd-java-agent-${project.version}.jar</argLine>
|
||||
<workingDirectory>target/FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
|
||||
</configuration>
|
||||
|
|
|
@ -14,4 +14,5 @@ public class AgentTracerConfig extends TracerConfig {
|
|||
public void setEnableCustomTracing(boolean enableCustomTracing) {
|
||||
this.enableCustomTracing = enableCustomTracing;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ import org.reflections.scanners.MethodAnnotationsScanner;
|
|||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import com.datadoghq.trace.resolver.AgentTracerConfig;
|
||||
import com.datadoghq.trace.resolver.DDTracerFactory;
|
||||
import com.datadoghq.trace.resolver.FactoryUtils;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
@ -43,8 +47,11 @@ public class TraceAnnotationsManager extends OpenTracingManager{
|
|||
OpenTracingManager.initialize(trans);
|
||||
OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader());
|
||||
|
||||
String value = System.getProperty("dd.enable_custom_tracing","false");
|
||||
if("true".equalsIgnoreCase(value)){
|
||||
//Load configuration
|
||||
AgentTracerConfig agentTracerConfig = FactoryUtils.loadConfigFromResource(DDTracerFactory.CONFIG_PATH, AgentTracerConfig.class);
|
||||
|
||||
//Check if annotations are enabled
|
||||
if(agentTracerConfig.isEnableCustomTracing()){
|
||||
loadRules(ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,3 +19,6 @@ sampler:
|
|||
# RateSample: only a portion of spans are reported to the writer
|
||||
# - Param 'rate': the portion of spans to keep
|
||||
type: AllSampler
|
||||
|
||||
# Enable custom tracing (annotations)
|
||||
# enableCustomTracing: true
|
|
@ -5,5 +5,3 @@ writer:
|
|||
port: 10000
|
||||
sampler:
|
||||
type: AllSampler
|
||||
|
||||
|
|
@ -1,17 +1,12 @@
|
|||
package com.datadoghq.trace.resolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.datadoghq.trace.integration.DDSpanContextDecorator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
|
||||
/**
|
||||
* Create DDSpaDecorators from a valid configuration
|
||||
|
@ -24,7 +19,6 @@ public class DDDecoratorsFactory {
|
|||
|
||||
public static final String CONFIG_PATH = "dd-trace-decorators.yaml";
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
|
||||
/**
|
||||
* Create decorators from configuration
|
||||
|
@ -77,22 +71,11 @@ public class DDDecoratorsFactory {
|
|||
}
|
||||
|
||||
public static List<DDSpanContextDecorator> createFromResources(){
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
List<DDSpanContextDecorator> result = new ArrayList<DDSpanContextDecorator>();
|
||||
try{
|
||||
Enumeration<URL> iter = classLoader.getResources(CONFIG_PATH);
|
||||
while (iter.hasMoreElements()) {
|
||||
TracerConfig config = objectMapper.readValue(iter.nextElement().openStream(), TracerConfig.class);
|
||||
TracerConfig config = FactoryUtils.loadConfigFromResource(CONFIG_PATH, TracerConfig.class);
|
||||
if(config!=null){
|
||||
result = DDDecoratorsFactory.create(config.getDecorators());
|
||||
|
||||
break; // ONLY the closest resource file is taken into account
|
||||
}
|
||||
}catch(IOException e){
|
||||
logger.error("Could not load decorators configuration file.", e);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package com.datadoghq.trace.resolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -15,8 +11,6 @@ import com.datadoghq.trace.writer.DDAgentWriter;
|
|||
import com.datadoghq.trace.writer.DDApi;
|
||||
import com.datadoghq.trace.writer.LoggingWritter;
|
||||
import com.datadoghq.trace.writer.Writer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
|
||||
/**
|
||||
* Create a tracer from a configuration file
|
||||
|
@ -26,8 +20,6 @@ public class DDTracerFactory {
|
|||
private final static Logger logger = LoggerFactory.getLogger(DDTracerFactory.class);
|
||||
|
||||
public static final String CONFIG_PATH = "dd-trace.yaml";
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
|
||||
|
||||
/**
|
||||
* Create a tracer from a TracerConfig object
|
||||
|
@ -67,26 +59,19 @@ public class DDTracerFactory {
|
|||
return new DDTracer(defaultServiceName, writer, rateSampler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static DDTracer createFromResources(){
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
TracerConfig tracerConfig = FactoryUtils.loadConfigFromResource(CONFIG_PATH, TracerConfig.class);
|
||||
|
||||
DDTracer tracer = null;
|
||||
try {
|
||||
Enumeration<URL> iter = classLoader.getResources(CONFIG_PATH);
|
||||
while (iter.hasMoreElements()) {
|
||||
TracerConfig config = objectMapper.readValue(iter.nextElement().openStream(), TracerConfig.class);
|
||||
|
||||
tracer = DDTracerFactory.create(config);
|
||||
|
||||
break; // ONLY the closest resource file is taken into account
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not load tracer configuration file.", e);
|
||||
}
|
||||
|
||||
if (tracer == null) {
|
||||
if (tracerConfig == null) {
|
||||
logger.info("No valid configuration file {} found. Loading default tracer.",CONFIG_PATH);
|
||||
tracer = new DDTracer();
|
||||
}else{
|
||||
tracer = DDTracerFactory.create(tracerConfig);
|
||||
}
|
||||
|
||||
return tracer;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.datadoghq.trace.resolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
|
||||
public class FactoryUtils {
|
||||
private final static Logger logger = LoggerFactory.getLogger(FactoryUtils.class);
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
|
||||
public static <A> A loadConfigFromResource(String resourceName, Class<A> targetClass){
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
A config = null;
|
||||
try {
|
||||
Enumeration<URL> iter = classLoader.getResources(resourceName);
|
||||
while (iter.hasMoreElements()) {
|
||||
config = objectMapper.readValue(iter.nextElement().openStream(), targetClass);
|
||||
|
||||
break; // ONLY the closest resource file is taken into account
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("Could not load configuration file {}.", resourceName);
|
||||
logger.error("Error when loading config file", e);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue