feat: get tests running, although failing due to instrumentation not being loaded properly
MODIFY
dd-java-agent/instrumentation/sparkjava-2.3/sparkjava-2.3.gradle
dd-java-agent/instrumentation/sparkjava-2.3/sparkjava-2.3.gradle
@@ -11,7 +11,7 @@ versionScan {
apply from: "${rootDir}/gradle/java.gradle"
-if (JavaVersion.current().isJava8Compatible()) {
+if (!JavaVersion.current().isJava8Compatible()) {
sourceSets {
test {
groovy {
@@ -26,6 +26,8 @@ if (JavaVersion.current().isJava8Compatible()) {
}
dependencies {
+ sourceCompatibility = "1.8"
+ targetCompatibility = "1.8"
compile project(':dd-java-agent:agent-tooling')
compile deps.bytebuddy

MODIFY
dd-java-agent/instrumentation/sparkjava-2.3/src/main/java/datadog/trace/instrumentation/sparkjava/RoutesInstrumentation.java
dd-java-agent/instrumentation/sparkjava-2.3/src/main/java/datadog/trace/instrumentation/sparkjava/RoutesInstrumentation.java
@@ -19,6 +19,11 @@ public class RoutesInstrumentation extends Instrumenter.Configurable {
super("sparkjava", "sparkjava-2.3");
}
+ @Override
+ public boolean defaultEnabled() {
+ return false;
+ }
+
@Override
public AgentBuilder apply(final AgentBuilder agentBuilder) {
return agentBuilder

MODIFY
dd-java-agent/instrumentation/sparkjava-2.3/src/test/groovy/SparkJavaBasedTest.groovy
dd-java-agent/instrumentation/sparkjava-2.3/src/test/groovy/SparkJavaBasedTest.groovy
import datadog.trace.agent.test.AgentTestRunner
+import datadog.trace.api.DDSpanTypes
import okhttp3.OkHttpClient
import okhttp3.Request
import spock.lang.Timeout
-@Timeout(5)
+@Timeout(20)
class SparkJavaBasedTest extends AgentTestRunner {
+ static {
+ TestSparkJavaApplication.initSpark()
+ }
+
private int port = 4567
OkHttpClient client = new OkHttpClient.Builder().build()
@@ -27,4 +32,38 @@ class SparkJavaBasedTest extends AgentTestRunner {
TEST_WRITER.size() == 1
}
+
+ def "generates spans"() {
+ setup:
+ def request = new Request.Builder()
+ .url("http://localhost:$port/param/asdf1234")
+ .get()
+ .build()
+ def response = client.newCall(request).execute()
+
+ expect:
+ response.body().string() == "Hello asdf1234"
+ TEST_WRITER.waitForTraces(1)
+ TEST_WRITER.size() == 1
+
+ def trace = TEST_WRITER.firstTrace()
+ trace.size() == 1
+ def span = trace[0]
+
+ span.context().operationName == "jetty.request"
+ span.context().resourceName == "GET /param/:param/"
+ span.context().spanType == DDSpanTypes.WEB_SERVLET
+ !span.context().getErrorFlag()
+ span.context().parentId == 0
+ span.context().tags["http.url"] == "http://localhost:$port/param/asdf1234/"
+ span.context().tags["http.method"] == "GET"
+ span.context().tags["span.kind"] == "server"
+ span.context().tags["span.type"] == "web"
+ span.context().tags["component"] == "java-web-servlet"
+ span.context().tags["http.status_code"] == 200
+ span.context().tags["thread.name"] != null
+ span.context().tags["thread.id"] != null
+ span.context().tags.size() == 8
+ }
+
}

MODIFY
dd-java-agent/instrumentation/sparkjava-2.3/src/test/java/TestSparkJavaApplication.java
dd-java-agent/instrumentation/sparkjava-2.3/src/test/java/TestSparkJavaApplication.java
@@ -2,8 +2,8 @@ import spark.Spark;
public class TestSparkJavaApplication {
- public static void main(final String[] args) {
-
+ public static void initSpark() {
+ Spark.port(4567);
Spark.get("/", (req, res) -> "Hello World");
Spark.get("/param/:param", (req, res) -> "Hello " + req.params("param"));
@@ -13,5 +13,7 @@ public class TestSparkJavaApplication {
(req, res) -> {
throw new RuntimeException(req.params("param"));
});
+ Spark.awaitInitialization();
}
+
}

feat: get tests running, although failing due to instrumentation not being loaded properly