Review fixes

This commit is contained in:
Tyler Benson 2019-08-02 10:01:03 -07:00
parent 9681b91f3e
commit 6f229305bb
8 changed files with 16 additions and 20 deletions

View File

@ -31,7 +31,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1 import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> { class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
@Shared @Shared
EventLoopGroup eventLoopGroup EventLoopGroup eventLoopGroup
@ -45,7 +45,6 @@ class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
.childHandler([ .childHandler([
initChannel: { ch -> initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline() ChannelPipeline pipeline = ch.pipeline()
// def handlers = [new HttpServerCodec()]
def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()] def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
handlers.each { pipeline.addLast(it) } handlers.each { pipeline.addLast(it) }
pipeline.addLast([ pipeline.addLast([

View File

@ -46,7 +46,6 @@ class Netty41ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
initChannel: { ch -> initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline() ChannelPipeline pipeline = ch.pipeline()
def handlers = [new HttpServerCodec()] def handlers = [new HttpServerCodec()]
// def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
handlers.each { pipeline.addLast(it) } handlers.each { pipeline.addLast(it) }
pipeline.addLast([ pipeline.addLast([
channelRead0 : { ctx, msg -> channelRead0 : { ctx, msg ->

View File

@ -85,11 +85,7 @@ public class Servlet3Advice {
// exception is thrown in filter chain, but status code is incorrect // exception is thrown in filter chain, but status code is incorrect
Tags.HTTP_STATUS.set(span, 500); Tags.HTTP_STATUS.set(span, 500);
} }
if (throwable.getCause() == null) { DECORATE.onError(span, throwable);
DECORATE.onError(span, throwable);
} else {
DECORATE.onError(span, throwable.getCause());
}
DECORATE.beforeFinish(span); DECORATE.beforeFinish(span);
req.removeAttribute(SERVLET_SPAN); req.removeAttribute(SERVLET_SPAN);
span.finish(); // Finish the span manually since finishSpanOnClose was false span.finish(); // Finish the span manually since finishSpanOnClose was false

View File

@ -4,6 +4,7 @@ import datadog.trace.agent.decorator.HttpServerDecorator;
import io.opentracing.Span; import io.opentracing.Span;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -59,4 +60,14 @@ public class Servlet3Decorator
} }
return super.onRequest(span, request); return super.onRequest(span, request);
} }
@Override
public Span onError(final Span span, final Throwable throwable) {
if (throwable instanceof ServletException && throwable.getCause() != null) {
super.onError(span, throwable.getCause());
} else {
super.onError(span, throwable);
}
return span;
}
} }

View File

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.AsyncEvent; import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
public class TagSettingAsyncListener implements AsyncListener { public class TagSettingAsyncListener implements AsyncListener {
@ -48,11 +47,7 @@ public class TagSettingAsyncListener implements AsyncListener {
// exception is thrown in filter chain, but status code is incorrect // exception is thrown in filter chain, but status code is incorrect
Tags.HTTP_STATUS.set(span, 500); Tags.HTTP_STATUS.set(span, 500);
} }
Throwable throwable = event.getThrowable(); DECORATE.onError(span, event.getThrowable());
if (throwable instanceof ServletException && throwable.getCause() != null) {
throwable = throwable.getCause();
}
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span); DECORATE.beforeFinish(span);
span.finish(); span.finish();
} }

View File

@ -94,10 +94,6 @@ abstract class AbstractServlet3Test<CONTEXT> extends HttpServerTest<Servlet3Deco
} }
"$Tags.HTTP_STATUS.key" endpoint.status "$Tags.HTTP_STATUS.key" endpoint.status
"$Tags.HTTP_URL.key" "${endpoint.resolve(address)}" "$Tags.HTTP_URL.key" "${endpoint.resolve(address)}"
// if (tagQueryString) {
// "$DDTags.HTTP_QUERY" uri.query
// "$DDTags.HTTP_FRAGMENT" { it == null || it == uri.fragment } // Optional
// }
"$Tags.PEER_HOSTNAME.key" { it == "localhost" || it == "127.0.0.1" } "$Tags.PEER_HOSTNAME.key" { it == "localhost" || it == "127.0.0.1" }
"$Tags.PEER_PORT.key" Integer "$Tags.PEER_PORT.key" Integer
"$Tags.PEER_HOST_IPV4.key" { it == null || it == "127.0.0.1" } // Optional "$Tags.PEER_HOST_IPV4.key" { it == null || it == "127.0.0.1" } // Optional

View File

@ -203,7 +203,7 @@ abstract class JettyDispatchTest extends JettyServlet3Test {
resourceName endpoint.status == 404 ? "404" : "GET ${endpoint.resolve(address).path}" resourceName endpoint.status == 404 ? "404" : "GET ${endpoint.resolve(address).path}"
spanType DDSpanTypes.HTTP_SERVER spanType DDSpanTypes.HTTP_SERVER
errored endpoint.errored errored endpoint.errored
// parent() // we can't reliably assert parent or child relationship here since both are tested.
tags { tags {
"servlet.context" "/$context" "servlet.context" "/$context"
"servlet.dispatch" endpoint.path "servlet.dispatch" endpoint.path

View File

@ -250,7 +250,7 @@ abstract class TomcatDispatchTest extends TomcatServlet3Test {
resourceName endpoint.status == 404 ? "404" : "GET ${endpoint.resolve(address).path}" resourceName endpoint.status == 404 ? "404" : "GET ${endpoint.resolve(address).path}"
spanType DDSpanTypes.HTTP_SERVER spanType DDSpanTypes.HTTP_SERVER
errored endpoint.errored errored endpoint.errored
// parent() // we can't reliably assert parent or child relationship here since both are tested.
tags { tags {
"servlet.context" "/$context" "servlet.context" "/$context"
"servlet.dispatch" endpoint.path "servlet.dispatch" endpoint.path