Remove tagsKV from annotation
MODIFY
dd-java-agent-ittests/pom.xml
dd-java-agent-ittests/pom.xml
<name>dd-java-agent-ittests</name>
<description>Datadog Java Agent integration tests</description>
<url>https://github.com/datadog/dd-trace-java</url>
- <packaging>pom</packaging>
<properties>

MODIFY
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/agent/SayTracedHello.java
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/agent/SayTracedHello.java
package com.datadoghq.trace.agent;
+import com.datadoghq.trace.DDTags;
import com.datadoghq.trace.Trace;
+import io.opentracing.tag.StringTag;
+import io.opentracing.util.GlobalTracer;
public class SayTracedHello {
- @Trace(operationName="SAY_HELLO",tagsKV={"service-name","test"})
+ @Trace(operationName="SAY_HELLO")
public static String sayHello(){
+ new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
return "hello!";
}
- @Trace(operationName="SAY_HA",tagsKV={"service-name","test","span-type","DB"})
+ @Trace(operationName="SAY_HA")
public static String sayHA(){
+ new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
+ new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().activeSpan(), "DB");
return "HA!!";
}
- @Trace(operationName="NEW_TRACE",tagsKV={"service-name","test2"})
+ @Trace(operationName="NEW_TRACE")
public static String sayHELLOsayHA(){
+ new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test2");
return sayHello()+sayHA();
}

MODIFY
dd-java-agent/README.md
dd-java-agent/README.md
@@ -152,10 +152,10 @@ public void myMethod() throws InterruptedException{
By default, the operation name attached to the spawn span will be the name of the method and no meta tags will be attached.
-You can use the `operationName` and `tagsKV` attributes to customize your trace:
+You can use the `operationName` customize your trace:
```java
-@Trace(operationName="Before DB",tagsKV={"mytag","myvalue"})
+@Trace(operationName="Before DB")
public void myMethod() throws InterruptedException{
....
}

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
@@ -172,7 +172,6 @@ public class TraceAnnotationsManager {
String ruleText =
CURRENT_SPAN_EXISTS+
buildSpan(javassistMethod)+
- buildWithTags(javassistMethod)+
START;
RuleScript script = createRuleScript("Start Active Span ",cc, javassistMethod, Location.create(LocationType.ENTRY,""),ruleText);
generatedScripts.append(script).append("\n");
@@ -264,26 +263,4 @@ public class TraceAnnotationsManager {
}
return BUILD_SPAN+javassistMethod.getName()+CLOSE_PARENTHESIS;
}
-
- private static String buildWithTags(CtMethod javassistMethod){
- try {
- Trace trace = (Trace) javassistMethod.getAnnotation(Trace.class);
- if(trace.tagsKV()!=null && trace.tagsKV().length>0){
- if(trace.tagsKV().length%2==0){
- StringBuilder sb = new StringBuilder();
- for(int i = 0;i<trace.tagsKV().length;i=i+2){
- sb.append(".withTag(\"")
- .append(trace.tagsKV()[i]).append("\",\"").append(trace.tagsKV()[i+1])
- .append(CLOSE_PARENTHESIS);
- }
- return sb.toString();
- }else{
- throw new IllegalArgumentException("The 'tagsKV' annotation attribute must define Key/Value pairs only");
- }
- }
- } catch (Exception e) {
- log.log(Level.WARNING, "Error when building injection rule on method " + javassistMethod + ". Fallback on default value.", e);
- }
- return "";
- }
}

MODIFY
dd-trace-annotations/src/main/java/com/datadoghq/trace/Trace.java
dd-trace-annotations/src/main/java/com/datadoghq/trace/Trace.java
@@ -17,10 +17,4 @@ public @interface Trace {
* The operation name to set. By default it takes the method's name
*/
String operationName() default "";
-
- /**
- * Tags Key/Values. Null by default, it sets only K/V String pairs such as {"service-name", "my-service", etc...}
- */
- String[] tagsKV() default {};
-
}

MODIFY
dd-trace-examples/dropwizard-mongo-client/pom.xml
dd-trace-examples/dropwizard-mongo-client/pom.xml
<version>${dd-trace.version}</version>
</dependency>
+ <!-- These dependencies are required for adding tags -->
+ <dependency>
+ <groupId>io.opentracing</groupId>
+ <artifactId>opentracing-api</artifactId>
+ <version>${opentracing.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.opentracing</groupId>
+ <artifactId>opentracing-util</artifactId>
+ <version>${opentracing.version}</version>
+ </dependency>
+
<!-- Application dependencies -->
<dependency>
<groupId>io.dropwizard</groupId>

MODIFY
dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/client/TracedClient.java
dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/client/TracedClient.java
@@ -3,6 +3,8 @@ package com.example.helloworld.client;
import java.io.IOException;
import com.datadoghq.trace.Trace;
+import io.opentracing.tag.StringTag;
+import io.opentracing.util.GlobalTracer;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@@ -21,8 +23,9 @@ public class TracedClient {
System.out.println("After execute");
}
- @Trace(tagsKV={"service-name","TracedClient"})
+ @Trace
private static void executeCall() throws IOException {
+ new StringTag("service-name").set(GlobalTracer.get().activeSpan(), "TracedClient");
OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder()

MODIFY
dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/SimpleCrudResource.java
dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/SimpleCrudResource.java
@@ -6,6 +6,8 @@ import com.google.common.base.Optional;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
+import io.opentracing.tag.StringTag;
+import io.opentracing.util.GlobalTracer;
import org.bson.Document;
import javax.ws.rs.GET;
@@ -101,24 +103,24 @@ public class SimpleCrudResource {
}
/**
- * The beforeDB is traced using the annotation @trace
- * Tags, the operation name can be configured using tagsKV and operationName options
+ * The beforeDB is traced using the annotation @trace with a custom operationName and a custom tag.
*
* @throws InterruptedException
*/
- @Trace(operationName = "Before DB", tagsKV = {"mytag", "myvalue"})
+ @Trace(operationName = "Before DB")
public void beforeDB() throws InterruptedException {
+ new StringTag("mytag").set(GlobalTracer.get().activeSpan(), "myvalue");
Thread.sleep(333);
}
/**
- * The beforeDB is traced using the annotation @trace
- * Tags, the operation name can be configured using tagsKV and operationName options
+ * The beforeDB is traced using the annotation @trace with a custom operationName and a custom tag.
*
* @throws InterruptedException
*/
- @Trace(operationName = "After DB", tagsKV = {"mytag", "myvalue"})
+ @Trace(operationName = "After DB")
public void afterDB() throws InterruptedException {
+ new StringTag("mytag").set(GlobalTracer.get().activeSpan(), "myvalue");
Thread.sleep(111);
}

Remove tagsKV from @Trace annotation