First version of the agent documentation

This commit is contained in:
renaudboutet 2017-05-24 13:06:20 +02:00
parent 2d06f7d271
commit b59551390f
3 changed files with 39 additions and 3 deletions

View File

@ -89,7 +89,43 @@ We also provide an [example project with Spring Boot & MySQL](web application fr
## Custom instrumentations ## Custom instrumentations
### The `@trace` annotation
By adding the `@trace` annotation to a method the `dd-java-agent` automatically measures the execution time.
```java
@Trace
public void myMethod() throws InterruptedException{
...
}
```
By default, the operation name attach to the spawn span will be the name of the method and no meta tags will be attached.
You can use the the `operationName` and `tagsKV` to change this:
```java
@Trace(operationName="Before DB",tagsKV={"mytag","myvalue"})
public void myMethod() throws InterruptedException{
....
}
```
### Enabling custom tracing
- Add the agent as a dependency of your project
```xml
<dependency>
<groupId>com.datadoghq</groupId>
<artifactId>dd-java-agent</artifactId>
<version>{version}</version>
</dependency>
```
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/).
- Enable custom tracing by adding this JVM property `-Ddd.enable_custom_tracing`
## Other useful resources ## Other useful resources

View File

@ -43,7 +43,7 @@ public class TraceAnnotationsManager extends OpenTracingManager{
OpenTracingManager.initialize(trans); OpenTracingManager.initialize(trans);
OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader()); OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader());
String value = System.getProperty("javaagent.enableAnnotations","false"); String value = System.getProperty("dd.enable_custom_tracing","false");
if("true".equalsIgnoreCase(value)){ if("true".equalsIgnoreCase(value)){
loadRules(ClassLoader.getSystemClassLoader()); loadRules(ClassLoader.getSystemClassLoader());
} }

View File

@ -64,12 +64,12 @@ public class HelloWorldResource {
return list; return list;
} }
@Trace(operationName="Before DB",tagsKV={"service-name","method"}) @Trace(operationName="Before DB",tagsKV={"mytag","myvalue"})
public void beforeDB() throws InterruptedException{ public void beforeDB() throws InterruptedException{
Thread.sleep(333); Thread.sleep(333);
} }
@Trace(operationName="After DB",tagsKV={"service-name","method"}) @Trace(operationName="After DB",tagsKV={"mytag","myvalue"})
public void afterDB() throws InterruptedException{ public void afterDB() throws InterruptedException{
Thread.sleep(111); Thread.sleep(111);
} }