Fixed NPE for error parser

This commit is contained in:
Marcin Grzejszczak
2017-06-30 11:29:53 +02:00
parent a159a87af7
commit c3e90e4e21
2 changed files with 8 additions and 3 deletions

View File

@@ -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);

View File

@@ -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");