Skip to content

Add compatibility tests for OpenTracing 0.31.0 #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion dd-trace-ot/dd-trace-ot.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ excludedClassesCoverage += [
apply plugin: 'org.unbroken-dome.test-sets'

testSets {
compatabilityTest
traceAgentTest
}

Expand All @@ -44,12 +45,17 @@ dependencies {

testCompile project(":dd-java-agent:testing")
testCompile project(':utils:gc-utils')
// testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.5'
testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.17.1'

traceAgentTestCompile deps.testcontainers
}

[configurations.compatabilityTestCompile, configurations.compatabilityTestRuntime].each {
it.resolutionStrategy {
force group: 'io.opentracing', name: 'opentracing-api', version: '0.31.0'
}
}

jmh {
// include = [".*URLAsResourceNameBenchmark"]
// include = ['some regular expression'] // include pattern (regular expression) for benchmarks to be executed
Expand Down
104 changes: 104 additions & 0 deletions dd-trace-ot/src/compatabilityTest/groovy/OT31ApiTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import datadog.opentracing.DDSpan
import datadog.opentracing.DDSpanContext
import datadog.opentracing.DDTracer
import datadog.opentracing.propagation.ExtractedContext
import datadog.trace.common.writer.ListWriter
import datadog.trace.util.test.DDSpecification
import io.opentracing.Tracer
import io.opentracing.propagation.Format
import io.opentracing.propagation.TextMap
import spock.lang.Subject

import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan

// This test focuses on things that are different between OpenTracing API 0.31.0 and 0.32.0
class OT31ApiTest extends DDSpecification {
static final WRITER = new ListWriter()

@Subject
Tracer tracer = new DDTracer(WRITER)

def "test startActive"() {
when:
def scope = tracer.buildSpan("some name").startActive(finishSpan)
scope.close()

then:
(scope.span() as DDSpan).isFinished() == finishSpan

where:
finishSpan << [true, false]
}

def "test startManual"() {
when:
tracer.buildSpan("some name").startManual().finish()

then:
assertTraces(WRITER, 1) {
trace(0, 1) {
basicSpan(it, 0, "some name")
}
}
}

def "test scopemanager"() {
setup:
def span = tracer.buildSpan("some name").start()

when:
tracer.scopeManager().activate(span, finishSpan) != null
tracer.scopeManager().active().span() == span

then:
tracer.scopeManager().active().close()
(span as DDSpan).isFinished() == finishSpan

where:
finishSpan << [true, false]
}

def "test inject extract"() {
setup:
def context = tracer.buildSpan("some name").start().context() as DDSpanContext
def textMap = [:]
def adapter = new TextMapAdapter(textMap)

when:
tracer.inject(context, Format.Builtin.TEXT_MAP, adapter)

then:
textMap == [
"x-datadog-trace-id" : context.traceId,
"x-datadog-parent-id" : context.spanId,
"x-datadog-sampling-priority": "$context.samplingPriority",
]

when:
def extract = tracer.extract(Format.Builtin.TEXT_MAP, adapter) as ExtractedContext

then:
extract.traceId == context.traceId
extract.spanId == context.spanId
extract.samplingPriority == context.samplingPriority
}

static class TextMapAdapter implements TextMap {
private final Map<String, String> map

TextMapAdapter(Map<String, String> map) {
this.map = map
}

@Override
Iterator<Map.Entry<String, String>> iterator() {
return map.entrySet().iterator()
}

@Override
void put(String key, String value) {
map.put(key, value)
}
}
}