Added verification for lack of response status code
With this change when there is no http response status code an exception is not thrown and the tags are not set for http.status_code
fixes #304
This commit is contained in:
@@ -216,6 +216,9 @@ public class TraceFilter extends GenericFilterBean {
|
||||
}
|
||||
|
||||
private boolean httpStatusSuccessful(HttpServletResponse response) {
|
||||
if (response.getStatus() == 0) {
|
||||
return false;
|
||||
}
|
||||
HttpStatus httpStatus = HttpStatus.valueOf(response.getStatus());
|
||||
return httpStatus.is2xxSuccessful() || httpStatus.is3xxRedirection();
|
||||
}
|
||||
@@ -308,7 +311,8 @@ public class TraceFilter extends GenericFilterBean {
|
||||
this.tracer.addTag(this.traceKeys.getHttp().getStatusCode(),
|
||||
String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
else if ((httpStatus < 200) || (httpStatus > 399)) {
|
||||
// only tag valid http statuses
|
||||
else if (httpStatus >= 100 && (httpStatus < 200) || (httpStatus > 399)) {
|
||||
this.tracer.addTag(this.traceKeys.getHttp().getStatusCode(),
|
||||
String.valueOf(response.getStatus()));
|
||||
}
|
||||
|
||||
@@ -131,6 +131,18 @@ public class TraceFilterTests {
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotStoreHttpStatusCodeWhenResponseCodeHasNotYetBeenSet() throws Exception {
|
||||
TraceFilter filter = new TraceFilter(this.tracer, this.traceKeys, this.spanReporter,
|
||||
this.spanExtractor, this.spanInjector, this.httpTraceKeysInjector);
|
||||
this.response.setStatus(0);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
assertThat(this.span.tags()).doesNotContainKey("http.status_code");
|
||||
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsNewTraceWithParentIdInHeaders() throws Exception {
|
||||
this.request = builder()
|
||||
|
||||
Reference in New Issue
Block a user