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>
|
</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/).
|
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>
|
</excludes>
|
||||||
<forkCount>3</forkCount>
|
<forkCount>3</forkCount>
|
||||||
<reuseForks>false</reuseForks>
|
<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>
|
-javaagent:${M2_REPO}/com/datadoghq/dd-java-agent/${project.version}/dd-java-agent-${project.version}.jar</argLine>
|
||||||
<workingDirectory>target/FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
|
<workingDirectory>target/FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -14,4 +14,5 @@ public class AgentTracerConfig extends TracerConfig {
|
||||||
public void setEnableCustomTracing(boolean enableCustomTracing) {
|
public void setEnableCustomTracing(boolean enableCustomTracing) {
|
||||||
this.enableCustomTracing = enableCustomTracing;
|
this.enableCustomTracing = enableCustomTracing;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,10 @@ import org.reflections.scanners.MethodAnnotationsScanner;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
import org.reflections.util.FilterBuilder;
|
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.ClassPool;
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
import javassist.CtMethod;
|
import javassist.CtMethod;
|
||||||
|
@ -43,8 +47,11 @@ public class TraceAnnotationsManager extends OpenTracingManager{
|
||||||
OpenTracingManager.initialize(trans);
|
OpenTracingManager.initialize(trans);
|
||||||
OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader());
|
OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader());
|
||||||
|
|
||||||
String value = System.getProperty("dd.enable_custom_tracing","false");
|
//Load configuration
|
||||||
if("true".equalsIgnoreCase(value)){
|
AgentTracerConfig agentTracerConfig = FactoryUtils.loadConfigFromResource(DDTracerFactory.CONFIG_PATH, AgentTracerConfig.class);
|
||||||
|
|
||||||
|
//Check if annotations are enabled
|
||||||
|
if(agentTracerConfig.isEnableCustomTracing()){
|
||||||
loadRules(ClassLoader.getSystemClassLoader());
|
loadRules(ClassLoader.getSystemClassLoader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,3 +19,6 @@ sampler:
|
||||||
# RateSample: only a portion of spans are reported to the writer
|
# RateSample: only a portion of spans are reported to the writer
|
||||||
# - Param 'rate': the portion of spans to keep
|
# - Param 'rate': the portion of spans to keep
|
||||||
type: AllSampler
|
type: AllSampler
|
||||||
|
|
||||||
|
# Enable custom tracing (annotations)
|
||||||
|
# enableCustomTracing: true
|
|
@ -5,5 +5,3 @@ writer:
|
||||||
port: 10000
|
port: 10000
|
||||||
sampler:
|
sampler:
|
||||||
type: AllSampler
|
type: AllSampler
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
package com.datadoghq.trace.resolver;
|
package com.datadoghq.trace.resolver;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.datadoghq.trace.integration.DDSpanContextDecorator;
|
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
|
* Create DDSpaDecorators from a valid configuration
|
||||||
|
@ -24,7 +19,6 @@ public class DDDecoratorsFactory {
|
||||||
|
|
||||||
public static final String CONFIG_PATH = "dd-trace-decorators.yaml";
|
public static final String CONFIG_PATH = "dd-trace-decorators.yaml";
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create decorators from configuration
|
* Create decorators from configuration
|
||||||
|
@ -77,22 +71,11 @@ public class DDDecoratorsFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DDSpanContextDecorator> createFromResources(){
|
public static List<DDSpanContextDecorator> createFromResources(){
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
List<DDSpanContextDecorator> result = new ArrayList<DDSpanContextDecorator>();
|
List<DDSpanContextDecorator> result = new ArrayList<DDSpanContextDecorator>();
|
||||||
try{
|
TracerConfig config = FactoryUtils.loadConfigFromResource(CONFIG_PATH, TracerConfig.class);
|
||||||
Enumeration<URL> iter = classLoader.getResources(CONFIG_PATH);
|
if(config!=null){
|
||||||
while (iter.hasMoreElements()) {
|
|
||||||
TracerConfig config = objectMapper.readValue(iter.nextElement().openStream(), TracerConfig.class);
|
|
||||||
result = DDDecoratorsFactory.create(config.getDecorators());
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.datadoghq.trace.resolver;
|
package com.datadoghq.trace.resolver;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.DDApi;
|
||||||
import com.datadoghq.trace.writer.LoggingWritter;
|
import com.datadoghq.trace.writer.LoggingWritter;
|
||||||
import com.datadoghq.trace.writer.Writer;
|
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
|
* Create a tracer from a configuration file
|
||||||
|
@ -26,8 +20,6 @@ public class DDTracerFactory {
|
||||||
private final static Logger logger = LoggerFactory.getLogger(DDTracerFactory.class);
|
private final static Logger logger = LoggerFactory.getLogger(DDTracerFactory.class);
|
||||||
|
|
||||||
public static final String CONFIG_PATH = "dd-trace.yaml";
|
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
|
* Create a tracer from a TracerConfig object
|
||||||
|
@ -67,26 +59,19 @@ public class DDTracerFactory {
|
||||||
return new DDTracer(defaultServiceName, writer, rateSampler);
|
return new DDTracer(defaultServiceName, writer, rateSampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static DDTracer createFromResources(){
|
public static DDTracer createFromResources(){
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
TracerConfig tracerConfig = FactoryUtils.loadConfigFromResource(CONFIG_PATH, TracerConfig.class);
|
||||||
|
|
||||||
DDTracer tracer = null;
|
DDTracer tracer = null;
|
||||||
try {
|
if (tracerConfig == null) {
|
||||||
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) {
|
|
||||||
logger.info("No valid configuration file {} found. Loading default tracer.",CONFIG_PATH);
|
logger.info("No valid configuration file {} found. Loading default tracer.",CONFIG_PATH);
|
||||||
tracer = new DDTracer();
|
tracer = new DDTracer();
|
||||||
|
}else{
|
||||||
|
tracer = DDTracerFactory.create(tracerConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracer;
|
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