spring-cloud-sleuth icon indicating copy to clipboard operation
spring-cloud-sleuth copied to clipboard

TraceContext not propgate to ErrorPage

Open yungoo opened this issue 8 years ago • 3 comments

i custom a 500 errorpage

 private static class CustomerErrorPageRegistrar implements ErrorPageRegistrar {

        // Register your error pages and url paths.
        @Override
        public void registerErrorPages(ErrorPageRegistry registry) {
            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error401");
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error404");
            ErrorPage error412Page = new ErrorPage(SignatureVerifyException.class, "/error403");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error");

            registry.addErrorPages(error401Page, error404Page, error412Page, error500Page);
        }

}

when i access tracer in ErrorPage controller

private String getTraceId() {
        final Tracer tracer = this.tracer.getIfAvailable();
        if (tracer != null) {
            return tracer.currentSpan().context().traceIdString();
        }
        return null;
}

then current span context report null.

with: spring-cloud-sleuth-core:2.0.0.M9

yungoo avatar Apr 18 '18 01:04 yungoo

we don't have a test like this in brave.. possibly we need to address it there in the brave-instrumentation-spring-webmvc project

On Wed, Apr 18, 2018 at 9:14 AM, yungoo [email protected] wrote:

i custom a 500 errorpage

` private static class CustomerErrorPageRegistrar implements ErrorPageRegistrar {

// Register your error pages and url paths.
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
    ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error401");
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error404");
    ErrorPage error412Page = new ErrorPage(SignatureVerifyException.class, "/error403");
    ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error");

    registry.addErrorPages(error401Page, error404Page, error412Page, error500Page);
}

}`

when i access tracer in ErrorPage controller

private String getTraceId() { final Tracer tracer = this.tracer.getIfAvailable(); if (tracer != null) { return tracer.currentSpan().context().traceIdString(); } return null; } tracer.currentSpan().context() is null

with: spring-cloud-sleuth-core:2.0.0.M9

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-sleuth/issues/948, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD617-qeDy3-K49VhYvTbjXOFMSFrT9ks5tppNogaJpZM4TZRYk .

codefromthecrypt avatar Apr 18 '18 01:04 codefromthecrypt

the unsuccessful request maybe redirect to error page, i think new scope should be created.

spring-cloud-sleuth-core:2.0.0.M8 works fine. Since TraceHandlerInterceptor will create a scope for it:

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler) throws Exception {
		String spanName = spanName(handler);
		boolean continueSpan = getRootSpanFromAttribute(request) != null;
		Span span = continueSpan ? getRootSpanFromAttribute(request) :
				httpTracing().tracing().tracer().nextSpan().name(spanName).start();
		try (Tracer.SpanInScope ws = httpTracing().tracing().tracer().withSpanInScope(span)) {
			if (log.isDebugEnabled()) {
				log.debug("Handling span " + span);
			}
			addClassMethodTag(handler, span);
			addClassNameTag(handler, span);
			setSpanInAttribute(request, span);
			if (!continueSpan) {
				setNewSpanCreatedAttribute(request, span);
			}
		}
		return true;
	}

but M9 no module will do this work.

Thanks for your great works. Best regards!

yungoo avatar Apr 18 '18 02:04 yungoo

This bug should probably be marked with milestone 2.0.0.RC2 since it was fixed by https://github.com/spring-cloud/spring-cloud-sleuth/pull/962

goober avatar May 08 '18 21:05 goober