Add netty server logging in tests
MODIFY
dd-java-agent/instrumentation/netty-3.8/src/latestDepTest/groovy/Netty38ServerTest.groovy
dd-java-agent/instrumentation/netty-3.8/src/latestDepTest/groovy/Netty38ServerTest.groovy
@@ -21,6 +21,8 @@ import org.jboss.netty.handler.codec.http.HttpResponseStatus
import org.jboss.netty.handler.codec.http.HttpServerCodec
import org.jboss.netty.handler.logging.LoggingHandler
import org.jboss.netty.logging.InternalLogLevel
+import org.jboss.netty.logging.InternalLoggerFactory
+import org.jboss.netty.logging.Slf4JLoggerFactory
import org.jboss.netty.util.CharsetUtil
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
@@ -37,8 +39,15 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
+ static final LoggingHandler LOGGING_HANDLER
+ static {
+ InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory())
+ LOGGING_HANDLER = new LoggingHandler(SERVER_LOGGER.name, InternalLogLevel.DEBUG, true)
+ }
+
ChannelPipeline channelPipeline() {
ChannelPipeline channelPipeline = new DefaultChannelPipeline()
+ channelPipeline.addFirst("logger", LOGGING_HANDLER)
channelPipeline.addLast("http-codec", new HttpServerCodec())
channelPipeline.addLast("controller", new SimpleChannelHandler() {
@@ -109,7 +118,7 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
@Override
ServerBootstrap startServer(int port) {
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory())
- bootstrap.setParentHandler(new LoggingHandler(InternalLogLevel.INFO))
+ bootstrap.setParentHandler(LOGGING_HANDLER)
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
ChannelPipeline getPipeline() throws Exception {

MODIFY
dd-java-agent/instrumentation/netty-3.8/src/test/groovy/Netty38ServerTest.groovy
dd-java-agent/instrumentation/netty-3.8/src/test/groovy/Netty38ServerTest.groovy
@@ -21,6 +21,8 @@ import org.jboss.netty.handler.codec.http.HttpResponseStatus
import org.jboss.netty.handler.codec.http.HttpServerCodec
import org.jboss.netty.handler.logging.LoggingHandler
import org.jboss.netty.logging.InternalLogLevel
+import org.jboss.netty.logging.InternalLoggerFactory
+import org.jboss.netty.logging.Slf4JLoggerFactory
import org.jboss.netty.util.CharsetUtil
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
@@ -37,8 +39,15 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
+ static final LoggingHandler LOGGING_HANDLER
+ static {
+ InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory())
+ LOGGING_HANDLER = new LoggingHandler(SERVER_LOGGER.name, InternalLogLevel.DEBUG, true)
+ }
+
ChannelPipeline channelPipeline() {
ChannelPipeline channelPipeline = new DefaultChannelPipeline()
+ channelPipeline.addFirst("logger", LOGGING_HANDLER)
channelPipeline.addLast("http-codec", new HttpServerCodec())
channelPipeline.addLast("controller", new SimpleChannelHandler() {
@@ -109,7 +118,7 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
@Override
ServerBootstrap startServer(int port) {
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory())
- bootstrap.setParentHandler(new LoggingHandler(InternalLogLevel.INFO))
+ bootstrap.setParentHandler(LOGGING_HANDLER)
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
ChannelPipeline getPipeline() throws Exception {

MODIFY
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
@@ -34,16 +34,20 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
class Netty40ServerTest extends HttpServerTest<EventLoopGroup> {
+ static final LoggingHandler LOGGING_HANDLER = new LoggingHandler(SERVER_LOGGER.name, LogLevel.DEBUG)
+
@Override
EventLoopGroup startServer(int port) {
def eventLoopGroup = new NioEventLoopGroup()
ServerBootstrap bootstrap = new ServerBootstrap()
.group(eventLoopGroup)
- .handler(new LoggingHandler(LogLevel.INFO))
+ .handler(LOGGING_HANDLER)
.childHandler([
initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline()
+ pipeline.addFirst("logger", LOGGING_HANDLER)
+
def handlers = [new HttpRequestDecoder(), new HttpResponseEncoder()]
handlers.each { pipeline.addLast(it) }
pipeline.addLast([

MODIFY
dd-java-agent/instrumentation/netty-4.1/src/test/groovy/Netty41ServerTest.groovy
dd-java-agent/instrumentation/netty-4.1/src/test/groovy/Netty41ServerTest.groovy
@@ -33,16 +33,20 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
class Netty41ServerTest extends HttpServerTest<EventLoopGroup> {
+ static final LoggingHandler LOGGING_HANDLER = new LoggingHandler(SERVER_LOGGER.name, LogLevel.DEBUG)
+
@Override
EventLoopGroup startServer(int port) {
def eventLoopGroup = new NioEventLoopGroup()
ServerBootstrap bootstrap = new ServerBootstrap()
.group(eventLoopGroup)
- .handler(new LoggingHandler(LogLevel.INFO))
+ .handler(LOGGING_HANDLER)
.childHandler([
initChannel: { ch ->
ChannelPipeline pipeline = ch.pipeline()
+ pipeline.addFirst("logger", LOGGING_HANDLER)
+
def handlers = [new HttpServerCodec()]
handlers.each { pipeline.addLast(it) }
pipeline.addLast([

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
package datadog.trace.agent.test.base
+import ch.qos.logback.classic.Level
import datadog.opentracing.DDSpan
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.asserts.ListWriterAssert
@@ -15,6 +16,8 @@ import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
import spock.lang.Shared
import spock.lang.Unroll
@@ -37,6 +40,11 @@ import static org.junit.Assume.assumeTrue
@Unroll
abstract class HttpServerTest<SERVER> extends AgentTestRunner {
+ public static final Logger SERVER_LOGGER = LoggerFactory.getLogger("http-server")
+ static {
+ ((ch.qos.logback.classic.Logger) SERVER_LOGGER).setLevel(Level.DEBUG)
+ }
+
@Shared
SERVER server
@Shared

Add netty server logging in tests