Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This supports the case where certain backend systems support errors as a first class object.
- Loading branch information
1 parent
b3e52c1
commit 46913be
Showing
21 changed files
with
301 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
package brave; | |||
|
|||
/** This is a simplified type used for parsing errors. It only allows annotations or tags. */ | |||
// This implementation allows a future type ScopedSpan which will not support backdated annotations | |||
public class ErrorParser { | |||
/** Adds no tags to the span representing the operation in error. */ | |||
public static final ErrorParser NOOP = new ErrorParser() { | |||
@Override protected void error(Throwable error, Object customizer) { | |||
} | |||
}; | |||
|
|||
/** Used to parse errors on a subtype of {@linkplain SpanCustomizer} */ | |||
public final void error(Throwable error, SpanCustomizer customizer) { | |||
error(error, (Object) customizer); | |||
} | |||
|
|||
/** | |||
* Override to change what data from the error are parsed into the span modeling it. By | |||
* default, this tags "error" as the message or simple name of the type. | |||
*/ | |||
protected void error(Throwable error, Object span) { | |||
String message = error.getMessage(); | |||
if (message == null) message = error.getClass().getSimpleName(); | |||
tag(span, "error", message); | |||
} | |||
|
|||
/** Same behaviour as {@link brave.SpanCustomizer#annotate(String)} */ | |||
protected final void annotate(Object span, String value) { | |||
if (span instanceof SpanCustomizer) { | |||
((SpanCustomizer) span).annotate(value); | |||
} | |||
} | |||
|
|||
/** Same behaviour as {@link brave.SpanCustomizer#tag(String, String)} */ | |||
protected final void tag(Object span, String key, String message) { | |||
if (span instanceof SpanCustomizer) { | |||
((SpanCustomizer) span).tag(key, message); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
package brave; | |||
|
|||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.junit.MockitoJUnitRunner; | |||
|
|||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
|
|||
@RunWith(MockitoJUnitRunner.class) | |||
public class ErrorParserTest { | |||
@Mock SpanCustomizer customizer; | |||
ErrorParser parser = new ErrorParser(); | |||
|
|||
@Test public void error() { | |||
parser.error(new RuntimeException("this cake is a lie"), customizer); | |||
|
|||
verify(customizer).tag("error", "this cake is a lie"); | |||
} | |||
|
|||
@Test public void error_noMessage() { | |||
parser.error(new RuntimeException(), customizer); | |||
|
|||
verify(customizer).tag("error", "RuntimeException"); | |||
} | |||
|
|||
@Test public void error_noop() { | |||
ErrorParser.NOOP.error(new RuntimeException("this cake is a lie"), customizer); | |||
|
|||
verifyNoMoreInteractions(customizer); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.