Skip to content

Commit 1a1767c

Browse files
author
Guillaume Polaert
authored
Merge pull request #32 from DataDog/tyler/remove-tagsKV
Remove tagsKV from @trace annotation
2 parents 07b2324 + bf15a13 commit 1a1767c

File tree

8 files changed

+36
-42
lines changed

8 files changed

+36
-42
lines changed

dd-java-agent-ittests/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<name>dd-java-agent-ittests</name>
1212
<description>Datadog Java Agent integration tests</description>
1313
<url>https://github.com/datadog/dd-trace-java</url>
14-
<packaging>pom</packaging>
1514

1615

1716
<properties>

dd-java-agent-ittests/src/test/java/com/datadoghq/trace/agent/SayTracedHello.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package com.datadoghq.trace.agent;
22

3+
import com.datadoghq.trace.DDTags;
34
import com.datadoghq.trace.Trace;
5+
import io.opentracing.tag.StringTag;
6+
import io.opentracing.util.GlobalTracer;
47

58
public class SayTracedHello {
69

7-
@Trace(operationName="SAY_HELLO",tagsKV={"service-name","test"})
10+
@Trace(operationName="SAY_HELLO")
811
public static String sayHello(){
12+
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
913
return "hello!";
1014
}
1115

12-
@Trace(operationName="SAY_HA",tagsKV={"service-name","test","span-type","DB"})
16+
@Trace(operationName="SAY_HA")
1317
public static String sayHA(){
18+
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
19+
new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().activeSpan(), "DB");
1420
return "HA!!";
1521
}
1622

17-
@Trace(operationName="NEW_TRACE",tagsKV={"service-name","test2"})
23+
@Trace(operationName="NEW_TRACE")
1824
public static String sayHELLOsayHA(){
25+
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test2");
1926
return sayHello()+sayHA();
2027
}
2128

dd-java-agent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ public void myMethod() throws InterruptedException{
152152

153153
By default, the operation name attached to the spawn span will be the name of the method and no meta tags will be attached.
154154

155-
You can use the `operationName` and `tagsKV` attributes to customize your trace:
155+
You can use the `operationName` customize your trace:
156156

157157
```java
158-
@Trace(operationName="Before DB",tagsKV={"mytag","myvalue"})
158+
@Trace(operationName="Before DB")
159159
public void myMethod() throws InterruptedException{
160160
....
161161
}

dd-java-agent/src/main/java/com/datadoghq/trace/agent/TraceAnnotationsManager.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public static void loadAnnotationsRules(String... scannedPackages) {
172172
String ruleText =
173173
CURRENT_SPAN_EXISTS+
174174
buildSpan(javassistMethod)+
175-
buildWithTags(javassistMethod)+
176175
START;
177176
RuleScript script = createRuleScript("Start Active Span ",cc, javassistMethod, Location.create(LocationType.ENTRY,""),ruleText);
178177
generatedScripts.append(script).append("\n");
@@ -264,26 +263,4 @@ private static String buildSpan(CtMethod javassistMethod){
264263
}
265264
return BUILD_SPAN+javassistMethod.getName()+CLOSE_PARENTHESIS;
266265
}
267-
268-
private static String buildWithTags(CtMethod javassistMethod){
269-
try {
270-
Trace trace = (Trace) javassistMethod.getAnnotation(Trace.class);
271-
if(trace.tagsKV()!=null && trace.tagsKV().length>0){
272-
if(trace.tagsKV().length%2==0){
273-
StringBuilder sb = new StringBuilder();
274-
for(int i = 0;i<trace.tagsKV().length;i=i+2){
275-
sb.append(".withTag(\"")
276-
.append(trace.tagsKV()[i]).append("\",\"").append(trace.tagsKV()[i+1])
277-
.append(CLOSE_PARENTHESIS);
278-
}
279-
return sb.toString();
280-
}else{
281-
throw new IllegalArgumentException("The 'tagsKV' annotation attribute must define Key/Value pairs only");
282-
}
283-
}
284-
} catch (Exception e) {
285-
log.log(Level.WARNING, "Error when building injection rule on method " + javassistMethod + ". Fallback on default value.", e);
286-
}
287-
return "";
288-
}
289266
}

dd-trace-annotations/src/main/java/com/datadoghq/trace/Trace.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,4 @@
1717
* The operation name to set. By default it takes the method's name
1818
*/
1919
String operationName() default "";
20-
21-
/**
22-
* Tags Key/Values. Null by default, it sets only K/V String pairs such as {"service-name", "my-service", etc...}
23-
*/
24-
String[] tagsKV() default {};
25-
2620
}

dd-trace-examples/dropwizard-mongo-client/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
<version>${dd-trace.version}</version>
2828
</dependency>
2929

30+
<!-- These dependencies are required for adding tags -->
31+
<dependency>
32+
<groupId>io.opentracing</groupId>
33+
<artifactId>opentracing-api</artifactId>
34+
<version>${opentracing.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.opentracing</groupId>
38+
<artifactId>opentracing-util</artifactId>
39+
<version>${opentracing.version}</version>
40+
</dependency>
41+
3042
<!-- Application dependencies -->
3143
<dependency>
3244
<groupId>io.dropwizard</groupId>

dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/client/TracedClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.IOException;
44

55
import com.datadoghq.trace.Trace;
6+
import io.opentracing.tag.StringTag;
7+
import io.opentracing.util.GlobalTracer;
68
import okhttp3.OkHttpClient;
79
import okhttp3.Request;
810
import okhttp3.Response;
@@ -21,8 +23,9 @@ public static void main(String[] args) throws Exception{
2123
System.out.println("After execute");
2224
}
2325

24-
@Trace(tagsKV={"service-name","TracedClient"})
26+
@Trace
2527
private static void executeCall() throws IOException {
28+
new StringTag("service-name").set(GlobalTracer.get().activeSpan(), "TracedClient");
2629
OkHttpClient client = new OkHttpClient().newBuilder().build();
2730

2831
Request request = new Request.Builder()

dd-trace-examples/dropwizard-mongo-client/src/main/java/com/example/helloworld/resources/SimpleCrudResource.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.mongodb.MongoClient;
77
import com.mongodb.client.MongoCursor;
88
import com.mongodb.client.MongoDatabase;
9+
import io.opentracing.tag.StringTag;
10+
import io.opentracing.util.GlobalTracer;
911
import org.bson.Document;
1012

1113
import javax.ws.rs.GET;
@@ -101,24 +103,24 @@ public List<Book> getBooks() throws InterruptedException {
101103
}
102104

103105
/**
104-
* The beforeDB is traced using the annotation @trace
105-
* Tags, the operation name can be configured using tagsKV and operationName options
106+
* The beforeDB is traced using the annotation @trace with a custom operationName and a custom tag.
106107
*
107108
* @throws InterruptedException
108109
*/
109-
@Trace(operationName = "Before DB", tagsKV = {"mytag", "myvalue"})
110+
@Trace(operationName = "Before DB")
110111
public void beforeDB() throws InterruptedException {
112+
new StringTag("mytag").set(GlobalTracer.get().activeSpan(), "myvalue");
111113
Thread.sleep(333);
112114
}
113115

114116
/**
115-
* The beforeDB is traced using the annotation @trace
116-
* Tags, the operation name can be configured using tagsKV and operationName options
117+
* The beforeDB is traced using the annotation @trace with a custom operationName and a custom tag.
117118
*
118119
* @throws InterruptedException
119120
*/
120-
@Trace(operationName = "After DB", tagsKV = {"mytag", "myvalue"})
121+
@Trace(operationName = "After DB")
121122
public void afterDB() throws InterruptedException {
123+
new StringTag("mytag").set(GlobalTracer.get().activeSpan(), "myvalue");
122124
Thread.sleep(111);
123125
}
124126

0 commit comments

Comments
 (0)