Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package springdata

import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
import datadog.opentracing.DDSpan
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.DDSpanTypes
import datadog.trace.instrumentation.api.Tags
Expand Down Expand Up @@ -34,13 +35,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
return repo
}

TEST_WRITER.clear()
runUnderTrace("setup") {
def applicationContext = new AnnotationConfigApplicationContext(Config)
repo = applicationContext.getBean(DocRepository)
}
TEST_WRITER.waitForTraces(1)
TEST_WRITER.clear()
def applicationContext = new AnnotationConfigApplicationContext(Config)
repo = applicationContext.getBean(DocRepository)

return repo
}
Expand Down Expand Up @@ -68,6 +64,7 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
!result.iterator().hasNext()

and:
waitForTracesAndSortSpans(1)
assertTraces(1) {
trace(0, 2) {
span(0) {
Expand Down Expand Up @@ -114,8 +111,31 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
repo.index(doc) == doc

and:
assertTraces(1) {
trace(0, 3) {
waitForTracesAndSortSpans(2)
// need to normalize trace ordering since they are finished by different threads
if (TEST_WRITER[1][0].resourceName == "PutMappingAction") {
def tmp = TEST_WRITER[1]
TEST_WRITER[1] = TEST_WRITER[0]
TEST_WRITER[0] = tmp
}
assertTraces(2) {
trace(0, 1) {
span(0) {
serviceName "elasticsearch"
resourceName "PutMappingAction"
operationName "elasticsearch.query"
spanType DDSpanTypes.ELASTICSEARCH
tags {
"$Tags.COMPONENT" "elasticsearch-java"
"$Tags.DB_TYPE" "elasticsearch"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"elasticsearch.action" "PutMappingAction"
"elasticsearch.request" "PutMappingRequest"
defaultTags()
}
}
}
trace(1, 3) {
span(0) {
resourceName "ElasticsearchRepository.index"
operationName "repository.operation"
Expand Down Expand Up @@ -174,6 +194,7 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
repo.findById("1").get() == doc

and:
waitForTracesAndSortSpans(1)
assertTraces(1) {
trace(0, 2) {
span(0) {
Expand Down Expand Up @@ -217,6 +238,7 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
repo.findById("1").get() == doc

and:
waitForTracesAndSortSpans(2)
assertTraces(2) {
trace(0, 3) {
span(0) {
Expand Down Expand Up @@ -309,6 +331,7 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
!repo.findAll().iterator().hasNext()

and:
waitForTracesAndSortSpans(2)
assertTraces(2) {
trace(0, 3) {
span(0) {
Expand Down Expand Up @@ -395,4 +418,17 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
where:
indexName = "test-index"
}

def waitForTracesAndSortSpans(int number) {
TEST_WRITER.waitForTraces(number)
for (List<DDSpan> trace : TEST_WRITER) {
// need to normalize span ordering since they are finished by different threads
if (trace.size() > 1 && trace[1].operationName == "repository.operation") {
def tmp = trace[1]
trace[1] = trace[0]
trace[0] = tmp
}
}
return true
}
}