Fix SpringJpaTest
MODIFY
dd-java-agent/instrumentation/hibernate/core-4.3/src/test/groovy/SpringJpaTest.groovy
dd-java-agent/instrumentation/hibernate/core-4.3/src/test/groovy/SpringJpaTest.groovy
@@ -26,16 +26,12 @@ class SpringJpaTest extends AgentTestRunner {
!repo.findAll().iterator().hasNext()
assertTraces(1) {
- trace(0, 2) {
+ trace(0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_"
spanType "sql"
}
- span(1) {
- serviceName "hsqldb"
- spanType "sql"
- childOf(span(0))
- }
}
}
TEST_WRITER.clear()
@@ -49,26 +45,23 @@ class SpringJpaTest extends AgentTestRunner {
// Behavior changed in new version:
def extraTrace = TEST_WRITER.size() == 2
assertTraces(extraTrace ? 2 : 1) {
- trace(0, 2) {
+ if (extraTrace) {
+ trace(0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "call next value for hibernate_sequence"
spanType "sql"
}
- span(1) {
- serviceName "hsqldb"
- spanType "sql"
- childOf(span(0))
}
}
- if (extraTrace) {
- trace(1, 1) {
+ trace(extraTrace ? 1 : 0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName ~/insert into Customer \(.*\) values \(.*, \?, \?\)/
spanType "sql"
}
}
}
- }
TEST_WRITER.clear()
when:
@@ -78,20 +71,17 @@ class SpringJpaTest extends AgentTestRunner {
then:
customer.id == savedId
assertTraces(2) {
- trace(0, 2) {
+ trace(0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?"
spanType "sql"
}
- span(1) {
- serviceName "hsqldb"
- spanType "sql"
- childOf(span(0))
- }
}
trace(1, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "update Customer set firstName=?, lastName=? where id=?"
spanType "sql"
}
}
@@ -105,16 +95,12 @@ class SpringJpaTest extends AgentTestRunner {
customer.id == savedId
customer.firstName == "Bill"
assertTraces(1) {
- trace(0, 2) {
+ trace(0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "select customer0_.id as id1_0_, customer0_.firstName as firstNam2_0_, customer0_.lastName as lastName3_0_ from Customer customer0_ where customer0_.lastName=?"
spanType "sql"
}
- span(1) {
- serviceName "hsqldb"
- spanType "sql"
- childOf(span(0))
- }
}
}
TEST_WRITER.clear()
@@ -124,20 +110,17 @@ class SpringJpaTest extends AgentTestRunner {
then:
assertTraces(2) {
- trace(0, 2) {
+ trace(0, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "select customer0_.id as id1_0_0_, customer0_.firstName as firstNam2_0_0_, customer0_.lastName as lastName3_0_0_ from Customer customer0_ where customer0_.id=?"
spanType "sql"
}
- span(1) {
- serviceName "hsqldb"
- spanType "sql"
- childOf(span(0))
- }
}
trace(1, 1) {
span(0) {
serviceName "hsqldb"
+ resourceName "delete from Customer where id=?"
spanType "sql"
}
}

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/SpanAssert.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/SpanAssert.groovy
@@ -4,6 +4,8 @@ import datadog.opentracing.DDSpan
import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType
+import java.util.regex.Pattern
+
import static TagsAssert.assertTags
class SpanAssert {
@@ -52,6 +54,11 @@ class SpanAssert {
checked.operationName = true
}
+ def resourceName(Pattern pattern) {
+ assert span.resourceName.matches(pattern)
+ checked.resourceName = true
+ }
+
def resourceName(String name) {
assert span.resourceName == name
checked.resourceName = true

Fix SpringJpaTest