Skip to content

Commit da2930a

Browse files
authored
Manage multiple SpanAttribute annotations (#9412)
1 parent 0ce85a2 commit da2930a

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/src/main/java/datadog/trace/instrumentation/opentelemetry/annotations/WithSpanDecorator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public void addTagsFromMethodArgs(AgentSpan span, Method method, Object[] args)
128128
if (name != null) {
129129
span.setTag(name, args[parameterIndex]);
130130
}
131-
break;
132131
}
133132
}
134133
}

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/src/test/groovy/SpanAttributeAnnotationTest.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,29 @@ class SpanAttributeAnnotationTest extends AgentTestRunner {
4040
'list' | ['value1', 'value2', 'value3']
4141
typeName = type.substring(0, 1).toUpperCase() + type.substring(1)
4242
}
43+
44+
def "test multiple SpanAttribute"() {
45+
setup:
46+
def methodName = "sayHelloWithMultipleAttributes"
47+
TracedMethods."$methodName"("param1", "param2")
48+
49+
expect:
50+
assertTraces(1) {
51+
trace(1) {
52+
span {
53+
resourceName "TracedMethods.$methodName"
54+
operationName "TracedMethods.$methodName"
55+
parent()
56+
errored false
57+
tags {
58+
defaultTags()
59+
"$Tags.COMPONENT" "opentelemetry"
60+
"custom-tag1" "param1"
61+
"custom-tag2" "param2"
62+
}
63+
}
64+
}
65+
}
66+
}
4367
}
4468

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/src/test/java/annotatedsample/TracedMethods.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public static String sayHelloWithListAttribute(@SpanAttribute("custom-tag") List
7575
return "hello!";
7676
}
7777

78+
@WithSpan
79+
public static String sayHelloWithMultipleAttributes(
80+
@SpanAttribute("custom-tag1") String param1, @SpanAttribute("custom-tag2") String param2) {
81+
return "hello!";
82+
}
83+
7884
@WithSpan
7985
public static void throwException() {
8086
throw new RuntimeException("Some exception");

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.26/src/test/groovy/AddingSpanAttributesAnnotationTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ class AddingSpanAttributesAnnotationTest extends AgentTestRunner {
4343
typeName = type.substring(0, 1).toUpperCase() + type.substring(1)
4444
}
4545

46+
def "test AddingSpanAttributes annotated method with multiple annotated parameters"() {
47+
setup:
48+
def methodName = "sayHelloWithMultipleAttributes"
49+
def testSpan = TEST_TRACER.startSpan("test", "operation")
50+
def scope = TEST_TRACER.activateManualSpan(testSpan)
51+
AnnotatedMethods."$methodName"("param1", "param2")
52+
scope.close()
53+
testSpan.finish()
54+
55+
expect:
56+
assertTraces(1) {
57+
trace(1) {
58+
span {
59+
resourceName "operation"
60+
operationName "operation"
61+
parent()
62+
errored false
63+
tags {
64+
defaultTags()
65+
"custom-tag1" "param1"
66+
"custom-tag2" "param2"
67+
}
68+
}
69+
}
70+
}
71+
}
72+
4673
def "test AddingSpanAttributes annotated method is skipped if no active span"() {
4774
setup:
4875
def testSpan = TEST_TRACER.startSpan("test", "operation")

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.26/src/test/java/annotatedsample/AnnotatedMethods.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public static String sayHelloWithLongAttribute(@SpanAttribute("custom-tag") long
2424
public static String sayHelloWithListAttribute(@SpanAttribute("custom-tag") List<?> param) {
2525
return "hello!";
2626
}
27+
28+
@AddingSpanAttributes
29+
public static String sayHelloWithMultipleAttributes(
30+
@SpanAttribute("custom-tag1") String param1, @SpanAttribute("custom-tag2") String param2) {
31+
return "hello!";
32+
}
2733
}

0 commit comments

Comments
 (0)