Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public void addTagsFromMethodArgs(AgentSpan span, Method method, Object[] args)
if (name != null) {
span.setTag(name, args[parameterIndex]);
}
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,29 @@ class SpanAttributeAnnotationTest extends AgentTestRunner {
'list' | ['value1', 'value2', 'value3']
typeName = type.substring(0, 1).toUpperCase() + type.substring(1)
}

def "test multiple SpanAttribute"() {
setup:
def methodName = "sayHelloWithMultipleAttributes"
TracedMethods."$methodName"("param1", "param2")

expect:
assertTraces(1) {
trace(1) {
span {
resourceName "TracedMethods.$methodName"
operationName "TracedMethods.$methodName"
parent()
errored false
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"custom-tag1" "param1"
"custom-tag2" "param2"
}
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public static String sayHelloWithListAttribute(@SpanAttribute("custom-tag") List
return "hello!";
}

@WithSpan
public static String sayHelloWithMultipleAttributes(
@SpanAttribute("custom-tag1") String param1, @SpanAttribute("custom-tag2") String param2) {
return "hello!";
}

@WithSpan
public static void throwException() {
throw new RuntimeException("Some exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,33 @@ class AddingSpanAttributesAnnotationTest extends AgentTestRunner {
typeName = type.substring(0, 1).toUpperCase() + type.substring(1)
}

def "test AddingSpanAttributes annotated method with multiple annotated parameters"() {
setup:
def methodName = "sayHelloWithMultipleAttributes"
def testSpan = TEST_TRACER.startSpan("test", "operation")
def scope = TEST_TRACER.activateManualSpan(testSpan)
AnnotatedMethods."$methodName"("param1", "param2")
scope.close()
testSpan.finish()

expect:
assertTraces(1) {
trace(1) {
span {
resourceName "operation"
operationName "operation"
parent()
errored false
tags {
defaultTags()
"custom-tag1" "param1"
"custom-tag2" "param2"
}
}
}
}
}

def "test AddingSpanAttributes annotated method is skipped if no active span"() {
setup:
def testSpan = TEST_TRACER.startSpan("test", "operation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public static String sayHelloWithLongAttribute(@SpanAttribute("custom-tag") long
public static String sayHelloWithListAttribute(@SpanAttribute("custom-tag") List<?> param) {
return "hello!";
}

@AddingSpanAttributes
public static String sayHelloWithMultipleAttributes(
@SpanAttribute("custom-tag1") String param1, @SpanAttribute("custom-tag2") String param2) {
return "hello!";
}
}