Custom HTTP status codes support (#460)
Provides custom HTTP status codes support without this change applications using custom HTTP status codes are currently having issues with Spring Cloud Sleuth. TraceFilter.httpStatusSuccessful() is throwing an IllegalArgumentException on HttpStatus.valueOf(response.getStatus()). with this change that gets fixed
This commit is contained in:
committed by
Marcin Grzejszczak
parent
64c2946d65
commit
85f8943410
@@ -249,8 +249,8 @@ public class TraceFilter extends GenericFilterBean {
|
||||
if (response.getStatus() == 0) {
|
||||
return false;
|
||||
}
|
||||
HttpStatus httpStatus = HttpStatus.valueOf(response.getStatus());
|
||||
return httpStatus.is2xxSuccessful() || httpStatus.is3xxRedirection();
|
||||
HttpStatus.Series httpStatusSeries = HttpStatus.Series.valueOf(response.getStatus());
|
||||
return httpStatusSeries == HttpStatus.Series.SUCCESSFUL || httpStatusSeries == HttpStatus.Series.REDIRECTION;
|
||||
}
|
||||
|
||||
private Span getSpanFromAttribute(HttpServletRequest request) {
|
||||
|
||||
@@ -325,6 +325,32 @@ public class TraceFilterTests {
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closesSpanWhenResponseStatusIs2xx() throws Exception {
|
||||
this.request = builder().header(Span.SPAN_ID_NAME, PARENT_ID)
|
||||
.header(Span.TRACE_ID_NAME, 20L).buildRequest(new MockServletContext());
|
||||
TraceFilter filter = new TraceFilter(this.tracer, this.traceKeys, this.spanReporter,
|
||||
this.spanExtractor, this.httpTraceKeysInjector);
|
||||
this.response.setStatus(200);
|
||||
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closesSpanWhenResponseStatusIs3xx() throws Exception {
|
||||
this.request = builder().header(Span.SPAN_ID_NAME, PARENT_ID)
|
||||
.header(Span.TRACE_ID_NAME, 20L).buildRequest(new MockServletContext());
|
||||
TraceFilter filter = new TraceFilter(this.tracer, this.traceKeys, this.spanReporter,
|
||||
this.spanExtractor, this.httpTraceKeysInjector);
|
||||
this.response.setStatus(302);
|
||||
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returns400IfSpanIsMalformedAndCreatesANewSpan() throws Exception {
|
||||
this.request = builder().header(Span.SPAN_ID_NAME, "asd")
|
||||
|
||||
Reference in New Issue
Block a user