Add okhttp request logging in tests
MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/OkHttpUtils.java
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/OkHttpUtils.java
@@ -2,6 +2,10 @@ package datadog.trace.agent.test.utils;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class was moved from groovy to java because groovy kept trying to introspect on the
@@ -9,9 +13,29 @@ import okhttp3.OkHttpClient;
*/
public class OkHttpUtils {
+ private static final Logger CLIENT_LOGGER = LoggerFactory.getLogger("http-client");
+
+ static {
+ ((ch.qos.logback.classic.Logger) CLIENT_LOGGER).setLevel(ch.qos.logback.classic.Level.DEBUG);
+ }
+
+ private static final HttpLoggingInterceptor LOGGING_INTERCEPTOR =
+ new HttpLoggingInterceptor(
+ new HttpLoggingInterceptor.Logger() {
+ @Override
+ public void log(final String message) {
+ CLIENT_LOGGER.debug(message);
+ }
+ });
+
+ static {
+ LOGGING_INTERCEPTOR.setLevel(Level.BASIC);
+ }
+
static OkHttpClient.Builder clientBuilder() {
final TimeUnit unit = TimeUnit.MINUTES;
return new OkHttpClient.Builder()
+ .addInterceptor(LOGGING_INTERCEPTOR)
.connectTimeout(1, unit)
.writeTimeout(1, unit)
.readTimeout(1, unit);

MODIFY
dd-java-agent/testing/testing.gradle
dd-java-agent/testing/testing.gradle
@@ -22,6 +22,7 @@ dependencies {
compile deps.guava
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '8.0.0.v20110901'
+ compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: versions.okhttp
compile project(':dd-java-agent:agent-tooling')
compile project(':utils:test-utils')

Add okhttp request logging in tests