0

I am using spring Boot Version 1.5.14.RELEASE with spring cloud sleuth zipkin. If I return a ResponseEntity setting its HttpStatus as BAD_REQUEST then I see the trace highlighted in Blue color. Is there a way to highlight the trace in Red color for a bad request with ResponseEntity object?

I explicitly threw a custom Exception for bad requests and saw the zipkin trace highlighted in Red color in Zipkin UI. But I don't want to do this as I am returning a body in ResponseEntity.

public  ResponseEntity<ResponseDto> saveRecord(Employee employee) {
    if(isValidated(employee)) {
        return new ResponseEntity<ResponseDto>(repo.save(employee), HttpStatus.OK);
    } else {
        return new ResponseEntity<ResponseDto>(service.handleErrorResponse(employee), HttpStatus.BAD_REQUEST);
    }
}

I expect the Zipkin trace to be highlighted in Red color as it is a bad request but the actual color is Blue.

Actual Trace

Expected Trace

  • We print it in red when an exception is thrown AFAIR. You're handling any exceptions so why should it be red? If you add an `error` tag with some additional description, then Zipkin will print it in red. – Marcin Grzejszczak Jul 22 '19 at 10:22
  • I am handling the exception as well as need to show the exception message in zipkin trace that is why.. – Johjen K Mathew Aug 27 '19 at 06:50

1 Answers1

1

I used an Aspect and from the returned ResponseEntity object, decided whether or not to programatically add an error tag to span. With this tag, zipkin will identify and highlight the trace in red colour. Below is the code snippet to add error tag to span.

import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
----
@Autowired
private Tracer tracer;

public void addErrorTag(String message) {
    Span currentSpan = tracer.getCurrentSpan();
    currentSpan.logEvent("ERROR: " + message);
    tracer.addTag("error", message);
}