Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,14 @@ class JSPInstrumentationBasicTests extends AgentTestRunner {
"span.origin.type" "org.apache.catalina.core.ApplicationFilterChain"
"servlet.context" "/$jspWebappContext"
"http.status_code" 500
errorTags(JasperException, String)
"error" true
"error.type" { String tagExceptionType ->
return tagExceptionType == exceptionClass.getName() || tagExceptionType.contains(exceptionClass.getSimpleName())
}
"error.msg" { String tagErrorMsg ->
return errorMessageOptional || tagErrorMsg instanceof String
}
"error.stack" String
defaultTags()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ 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.HttpVersion.HTTP_1_1

class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
@Shared
EventLoopGroup eventLoopGroup

@Override
void startServer(int port) {
// def handlers = [new HttpServerCodec()]
def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
eventLoopGroup = new NioEventLoopGroup()

ServerBootstrap bootstrap = new ServerBootstrap()
Expand All @@ -47,6 +45,7 @@ class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
.childHandler([
initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline()
def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
handlers.each { pipeline.addLast(it) }
pipeline.addLast([
channelRead0 : { ctx, msg ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public AgentBuilder instrument(final AgentBuilder agentBuilder) {
.transform(
new AgentBuilder.Transformer.ForAdvice()
.advice(
named("fireChannelRead"),
HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
named("channelRead"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class Netty41ServerTest extends HttpServerTest<NettyHttpServerDecorator> {

@Override
void startServer(int port) {
def handlers = [new HttpServerCodec()]
// def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
eventLoopGroup = new NioEventLoopGroup()

ServerBootstrap bootstrap = new ServerBootstrap()
Expand All @@ -47,6 +45,7 @@ class Netty41ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
.childHandler([
initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline()
def handlers = [new HttpServerCodec()]
handlers.each { pipeline.addLast(it) }
pipeline.addLast([
channelRead0 : { ctx, msg ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public AgentBuilder instrument(final AgentBuilder agentBuilder) {
.transform(
new AgentBuilder.Transformer.ForAdvice()
.advice(
named("fireChannelRead"),
HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
named("channelRead"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
}
}
1 change: 1 addition & 0 deletions dd-java-agent/instrumentation/servlet-3/servlet-3.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
testCompile(project(':dd-java-agent:testing')) {
exclude group: 'org.eclipse.jetty', module: 'jetty-server'
}
testCompile project(':dd-java-agent:instrumentation:java-concurrent')
testCompile project(':dd-java-agent:instrumentation:jetty-8') // See if there's any conflicts.
testCompile group: 'org.eclipse.jetty', name: 'jetty-server', version: '8.2.0.v20160908'
testCompile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '8.2.0.v20160908'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static Scope startSpan(
final Scope scope =
GlobalTracer.get()
.buildSpan("servlet.request")
.ignoreActiveSpan()
.asChildOf(extractedContext)
.withTag("span.origin.type", servlet.getClass().getName())
.startActive(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.opentracing.Span;
import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -59,4 +60,14 @@ public Span onRequest(final Span span, final HttpServletRequest 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void onTimeout(final AsyncEvent event) throws IOException {
@Override
public void onError(final AsyncEvent event) throws IOException {
if (event.getThrowable() != null && activated.compareAndSet(false, true)) {
DECORATE.onResponse(span, (HttpServletResponse) event.getSuppliedResponse());
if (((HttpServletResponse) event.getSuppliedResponse()).getStatus()
== HttpServletResponse.SC_OK) {
// exception is thrown in filter chain, but status code is incorrect
Expand All @@ -52,9 +53,9 @@ public void onError(final AsyncEvent event) throws IOException {
}
}

/** Finish current span on dispatch. New listener will be attached by Servlet3Advice */
/** Transfer the listener over to the new context. */
@Override
public void onStartAsync(final AsyncEvent event) throws IOException {
onComplete(event);
event.getAsyncContext().addListener(this);
}
}
Loading