Fixed NPE for error parser
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package org.springframework.cloud.sleuth;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.sleuth.util.ExceptionUtils;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
/**
|
||||
* {@link ErrorParser} that sets the error tag for an exportable span.
|
||||
*
|
||||
@@ -17,7 +17,7 @@ public class ExceptionMessageErrorParser implements ErrorParser {
|
||||
|
||||
@Override
|
||||
public void parseErrorTags(Span span, Throwable error) {
|
||||
if (span.isExportable()) {
|
||||
if (span != null && span.isExportable()) {
|
||||
String errorMsg = ExceptionUtils.getExceptionMessage(error);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding an error tag [" + errorMsg + "] to span " + span);
|
||||
|
||||
@@ -19,6 +19,11 @@ public class ExceptionMessageErrorParserTests {
|
||||
then(span).hasATag("error", "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_throw_an_exception_when_span_is_null() throws Exception {
|
||||
new ExceptionMessageErrorParser().parseErrorTags(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_append_tag_for_non_exportable_span() throws Exception {
|
||||
Throwable e = new RuntimeException("foo");
|
||||
|
||||
Reference in New Issue
Block a user