Use OkHttpUtils in more places
MODIFY
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy
import datadog.trace.agent.test.AgentTestRunner
+import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import io.opentracing.tag.Tags
-import okhttp3.OkHttpClient
import okhttp3.Request
import spock.lang.Shared
@@ -18,6 +18,9 @@ class AkkaHttpServerInstrumentationTest extends AgentTestRunner {
@Shared
int syncPort
+ @Shared
+ def client = OkHttpUtils.client()
+
def setupSpec() {
AkkaHttpTestAsyncWebServer.start()
asyncPort = AkkaHttpTestAsyncWebServer.port()
@@ -32,7 +35,6 @@ class AkkaHttpServerInstrumentationTest extends AgentTestRunner {
def "#server 200 request trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/test")
.header("x-datadog-trace-id", "123")
@@ -79,7 +81,6 @@ class AkkaHttpServerInstrumentationTest extends AgentTestRunner {
def "#server exceptions trace for #endpoint"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/$endpoint")
.get()
@@ -120,7 +121,6 @@ class AkkaHttpServerInstrumentationTest extends AgentTestRunner {
def "#server 5xx trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/server-error")
.get()
@@ -160,7 +160,6 @@ class AkkaHttpServerInstrumentationTest extends AgentTestRunner {
def "#server 4xx trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/not-found")
.get()

MODIFY
dd-java-agent/instrumentation/play-2.4/src/latestDepTest/groovy/Play26Test.groovy
dd-java-agent/instrumentation/play-2.4/src/latestDepTest/groovy/Play26Test.groovy
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestUtils
+import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.api.DDSpanTypes
-import okhttp3.OkHttpClient
import okhttp3.Request
import play.api.test.TestServer
import play.test.Helpers
@@ -19,6 +19,9 @@ class Play26Test extends AgentTestRunner {
@Shared
TestServer testServer
+ @Shared
+ def client = OkHttpUtils.client()
+
def setupSpec() {
port = TestUtils.randomOpenPort()
testServer = Helpers.testServer(port, Play26TestUtils.buildTestApp())
@@ -31,7 +34,6 @@ class Play26Test extends AgentTestRunner {
def "request traces"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/helloplay/spock")
.header("x-datadog-trace-id", "123")
@@ -88,7 +90,6 @@ class Play26Test extends AgentTestRunner {
def "5xx errors trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/make-error")
.get()
@@ -139,7 +140,6 @@ class Play26Test extends AgentTestRunner {
def "error thrown in request"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/exception")
.get()
@@ -194,7 +194,6 @@ class Play26Test extends AgentTestRunner {
def "4xx errors trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/nowhere")
.get()

MODIFY
dd-java-agent/instrumentation/play-2.4/src/test/groovy/Play24Test.groovy
dd-java-agent/instrumentation/play-2.4/src/test/groovy/Play24Test.groovy
import datadog.opentracing.DDSpan
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestUtils
+import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.api.DDSpanTypes
-import okhttp3.OkHttpClient
import okhttp3.Request
import play.api.test.TestServer
import play.test.Helpers
@@ -14,6 +14,9 @@ class Play24Test extends AgentTestRunner {
@Shared
TestServer testServer
+ @Shared
+ def client = OkHttpUtils.client()
+
def setupSpec() {
port = TestUtils.randomOpenPort()
testServer = Helpers.testServer(port, Play24TestUtils.buildTestApp())
@@ -26,7 +29,6 @@ class Play24Test extends AgentTestRunner {
def "request traces"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/helloplay/spock")
.header("x-datadog-trace-id", "123")
@@ -63,7 +65,6 @@ class Play24Test extends AgentTestRunner {
def "5xx errors trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/make-error")
.get()
@@ -91,7 +92,6 @@ class Play24Test extends AgentTestRunner {
def "error thrown in request"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/exception")
.get()
@@ -122,7 +122,6 @@ class Play24Test extends AgentTestRunner {
def "4xx errors trace"() {
setup:
- OkHttpClient client = new OkHttpClient.Builder().build()
def request = new Request.Builder()
.url("http://localhost:$port/nowhere")
.get()

MODIFY
dd-java-agent/testing/src/test/groovy/server/ServerTest.groovy
dd-java-agent/testing/src/test/groovy/server/ServerTest.groovy
@@ -5,7 +5,6 @@ import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.common.writer.ListWriter
import okhttp3.MultipartBody
-import okhttp3.OkHttpClient
import okhttp3.Request
import spock.lang.Shared
@@ -13,7 +12,6 @@ import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer
/* Don't actually need AgentTestRunner, but it messes up the classloader for AgentTestRunnerTest if this runs first. */
-
class ServerTest extends AgentTestRunner {
@Shared
def client = OkHttpUtils.client()
@@ -233,7 +231,7 @@ class ServerTest extends AgentTestRunner {
def "server redirect"() {
setup:
- client = new OkHttpClient().newBuilder().followRedirects(followRedirects).build()
+ client = OkHttpUtils.clientBuilder().followRedirects(followRedirects).build()
def server = httpServer {
handlers {
get("/redirect") {

Use OkHttpUtils in more places