diff --git a/dd-java-agent/Readme.md b/dd-java-agent/Readme.md index a1a1500b77..ca577d1706 100644 --- a/dd-java-agent/Readme.md +++ b/dd-java-agent/Readme.md @@ -89,7 +89,43 @@ We also provide an [example project with Spring Boot & MySQL](web application fr ## 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 + + com.datadoghq + dd-java-agent + {version} + +``` + +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 diff --git a/dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java b/dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java index f1bb4cac50..6a9e9debc8 100644 --- a/dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java +++ b/dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java @@ -43,7 +43,7 @@ public class TraceAnnotationsManager extends OpenTracingManager{ OpenTracingManager.initialize(trans); OpenTracingManager.loadRules(ClassLoader.getSystemClassLoader()); - String value = System.getProperty("javaagent.enableAnnotations","false"); + String value = System.getProperty("dd.enable_custom_tracing","false"); if("true".equalsIgnoreCase(value)){ loadRules(ClassLoader.getSystemClassLoader()); } diff --git a/dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/HelloWorldResource.java b/dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/HelloWorldResource.java index 17606447b5..4a0aaacb9a 100644 --- a/dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/HelloWorldResource.java +++ b/dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/HelloWorldResource.java @@ -64,12 +64,12 @@ public class HelloWorldResource { return list; } - @Trace(operationName="Before DB",tagsKV={"service-name","method"}) + @Trace(operationName="Before DB",tagsKV={"mytag","myvalue"}) public void beforeDB() throws InterruptedException{ Thread.sleep(333); } - @Trace(operationName="After DB",tagsKV={"service-name","method"}) + @Trace(operationName="After DB",tagsKV={"mytag","myvalue"}) public void afterDB() throws InterruptedException{ Thread.sleep(111); }