Fixed invalid reading from 'key' attribute of SpanTag; fixes #800
This commit is contained in:
@@ -45,7 +45,6 @@ public @interface SpanTag {
|
||||
/**
|
||||
* The name of the key of the tag which should be created.
|
||||
*/
|
||||
@AliasFor("key")
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,10 +121,16 @@ class SpanTagAnnotationHandler {
|
||||
private void addAnnotatedArguments(List<SleuthAnnotatedParameter> toBeAdded) {
|
||||
for (SleuthAnnotatedParameter container : toBeAdded) {
|
||||
String tagValue = resolveTagValue(container.annotation, container.argument);
|
||||
tracer().addTag(container.annotation.value(), tagValue);
|
||||
String tagKey = resolveTagKey(container);
|
||||
tracer().addTag(tagKey, tagValue);
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveTagKey(SleuthAnnotatedParameter container) {
|
||||
return StringUtils.hasText(container.annotation.value()) ?
|
||||
container.annotation.value() : container.annotation.key();
|
||||
}
|
||||
|
||||
String resolveTagValue(SpanTag annotation, Object argument) {
|
||||
if (argument == null) {
|
||||
return "";
|
||||
|
||||
@@ -149,6 +149,22 @@ public class SleuthSpanCreatorAspectTests {
|
||||
then(ExceptionUtils.getLastException()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContinueSpanWhenKeyIsUsedOnSpanTagWhenAnnotationOnInterfaceMethod() {
|
||||
Span span = this.tracer.createSpan("foo");
|
||||
|
||||
this.testBean.testMethod10_v2("test");
|
||||
|
||||
this.tracer.close(span);
|
||||
List<Span> spans = new ArrayList<>(this.accumulator.getSpans());
|
||||
then(new ListOfSpans(spans)).hasSize(1)
|
||||
.hasASpanWithName("foo")
|
||||
.hasASpanWithTagEqualTo("customTestTag10", "test")
|
||||
.hasASpanWithLogEqualTo("customTest.before")
|
||||
.hasASpanWithLogEqualTo("customTest.after");
|
||||
then(ExceptionUtils.getLastException()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContinueSpanWithLogWhenAnnotationOnClassMethod() {
|
||||
Span span = this.tracer.createSpan("foo");
|
||||
@@ -244,7 +260,10 @@ public class SleuthSpanCreatorAspectTests {
|
||||
void testMethod9(String param);
|
||||
|
||||
@ContinueSpan(log = "customTest")
|
||||
void testMethod10(@SpanTag("testTag10") String param);
|
||||
void testMethod10(@SpanTag(value = "testTag10") String param);
|
||||
|
||||
@ContinueSpan(log = "customTest")
|
||||
void testMethod10_v2(@SpanTag(key = "testTag10") String param);
|
||||
|
||||
// tag::continue_span[]
|
||||
@ContinueSpan(log = "testMethod11")
|
||||
@@ -306,7 +325,12 @@ public class SleuthSpanCreatorAspectTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMethod10(@SpanTag("customTestTag10") String param) {
|
||||
public void testMethod10(@SpanTag(value = "customTestTag10") String param) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMethod10_v2(@SpanTag(key = "customTestTag10") String param) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user