Skip to content

Commit d8d6af0

Browse files
authored
ServiceTalk Captured Context API Instrumentation for v0.42.56+ (#8821)
1 parent 3d7db54 commit d8d6af0

File tree

15 files changed

+859
-208
lines changed

15 files changed

+859
-208
lines changed
Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1 @@
1-
plugins {
2-
id 'java-test-fixtures'
3-
}
4-
5-
muzzle {
6-
pass {
7-
group = 'io.servicetalk'
8-
module = 'servicetalk-concurrent-api'
9-
// prev versions missing ContextMap
10-
versions = '[0.41.12,)'
11-
assertInverse = true
12-
}
13-
pass {
14-
group = 'io.servicetalk'
15-
module = 'servicetalk-context-api'
16-
versions = '[0.1.0,)'
17-
assertInverse = true
18-
}
19-
}
20-
21-
ext {
22-
minJavaVersionForTests = JavaVersion.VERSION_11
23-
}
24-
251
apply from: "$rootDir/gradle/java.gradle"
26-
27-
addTestSuiteForDir('latestDepTest', 'test')
28-
29-
dependencies {
30-
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.45'
31-
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.45'
32-
33-
testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.0'
34-
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.0'
35-
36-
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '+'
37-
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '+'
38-
}
39-

dd-java-agent/instrumentation/servicetalk/gradle.lockfile

Lines changed: 119 additions & 145 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'java-test-fixtures'
3+
}
4+
5+
muzzle {
6+
pass {
7+
group = 'io.servicetalk'
8+
module = 'servicetalk-concurrent-api'
9+
versions = '[0.42.0,0.42.55]'
10+
}
11+
fail {
12+
group = 'io.servicetalk'
13+
module = 'servicetalk-concurrent-api'
14+
versions = '(0.42.55,]'
15+
}
16+
}
17+
18+
ext {
19+
minJavaVersionForTests = JavaVersion.VERSION_11
20+
}
21+
22+
apply from: "$rootDir/gradle/java.gradle"
23+
24+
addTestSuiteForDir('latestDepTest', 'test')
25+
26+
dependencies {
27+
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.0'
28+
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.0'
29+
30+
testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.42'
31+
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.42'
32+
33+
// import the newer instrumentation into the test to ensure that it does not interfere with it
34+
testRuntimeOnly project(":dd-java-agent:instrumentation:servicetalk:servicetalk-0.42.56")
35+
36+
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.55'
37+
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.55'
38+
}
39+

dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/gradle.lockfile

Lines changed: 185 additions & 0 deletions
Large diffs are not rendered by default.

dd-java-agent/instrumentation/servicetalk/src/main/java/datadog/trace/instrumentation/servicetalk/ContextMapInstrumentation.java renamed to dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/src/main/java/datadog/trace/instrumentation/servicetalk0_42_0/ContextMapInstrumentation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package datadog.trace.instrumentation.servicetalk;
1+
package datadog.trace.instrumentation.servicetalk0_42_0;
22

33
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
44
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
@@ -16,7 +16,7 @@
1616
import net.bytebuddy.asm.Advice;
1717

1818
@AutoService(InstrumenterModule.class)
19-
public class ContextMapInstrumentation extends AbstractAsyncContextInstrumentation
19+
public class ContextMapInstrumentation extends ServiceTalkInstrumentation
2020
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
2121

2222
@Override
@@ -40,6 +40,8 @@ public void methodAdvice(MethodTransformer transformer) {
4040
private static final class Construct {
4141
@Advice.OnMethodExit(suppress = Throwable.class)
4242
public static void exit(@Advice.This ContextMap contextMap) {
43+
// Capture an active span on ST context copy to support versions prior to 0.42.56 that did not
44+
// have captureContext
4345
InstrumentationContext.get(ContextMap.class, AgentSpan.class)
4446
.put(contextMap, AgentTracer.activeSpan());
4547
}

dd-java-agent/instrumentation/servicetalk/src/main/java/datadog/trace/instrumentation/servicetalk/ContextPreservingInstrumentation.java renamed to dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/src/main/java/datadog/trace/instrumentation/servicetalk0_42_0/ContextPreservingInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package datadog.trace.instrumentation.servicetalk;
1+
package datadog.trace.instrumentation.servicetalk0_42_0;
22

33
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.namedOneOf;
44

@@ -13,7 +13,7 @@
1313
import net.bytebuddy.asm.Advice;
1414

1515
@AutoService(InstrumenterModule.class)
16-
public class ContextPreservingInstrumentation extends AbstractAsyncContextInstrumentation
16+
public class ContextPreservingInstrumentation extends ServiceTalkInstrumentation
1717
implements Instrumenter.ForKnownTypes, Instrumenter.HasMethodAdvice {
1818

1919
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package datadog.trace.instrumentation.servicetalk0_42_0;
2+
3+
import datadog.trace.agent.tooling.InstrumenterModule;
4+
import datadog.trace.agent.tooling.muzzle.Reference;
5+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
6+
import java.util.Collections;
7+
import java.util.Map;
8+
9+
public abstract class ServiceTalkInstrumentation extends InstrumenterModule.Tracing {
10+
11+
public ServiceTalkInstrumentation() {
12+
super("servicetalk", "servicetalk-concurrent");
13+
}
14+
15+
@Override
16+
public Map<String, String> contextStore() {
17+
return Collections.singletonMap(
18+
"io.servicetalk.context.api.ContextMap", AgentSpan.class.getName());
19+
}
20+
21+
@Override
22+
public Reference[] additionalMuzzleReferences() {
23+
return new Reference[] {
24+
// This check prevents older instrumentation from being applied to ServiceTalk v0.42.56+
25+
new Reference.Builder("io.servicetalk.concurrent.api.DelegatingExecutor")
26+
// Removed in v0.42.56
27+
.withField(new String[0], 0, "delegate", "Lio/servicetalk/concurrent/api/Executor;")
28+
.build(),
29+
};
30+
}
31+
}

dd-java-agent/instrumentation/servicetalk/src/test/groovy/ContextPreservingInstrumentationTest.groovy renamed to dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/src/test/groovy/ContextPreservingInstrumentationTest.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import datadog.trace.bootstrap.instrumentation.api.AgentScope
33
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
44
import io.servicetalk.concurrent.api.AsyncContext
55
import io.servicetalk.context.api.ContextMap
6-
76
import java.util.concurrent.ExecutorService
87
import java.util.concurrent.Executors
98

@@ -150,7 +149,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
150149
}
151150
}
152151

153-
private childSpan() {
152+
private static childSpan() {
154153
AgentTracer.startSpan("test", "child").finish()
155154
}
156155
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id 'java-test-fixtures'
3+
}
4+
5+
muzzle {
6+
fail {
7+
group = 'io.servicetalk'
8+
module = 'servicetalk-concurrent-api'
9+
versions = '[,0.42.56)'
10+
}
11+
pass {
12+
group = 'io.servicetalk'
13+
module = 'servicetalk-concurrent-api'
14+
// 0.42.56 is the earliest version where CapturedContext is public
15+
versions = '[0.42.56,]'
16+
}
17+
}
18+
19+
ext {
20+
minJavaVersionForTests = JavaVersion.VERSION_11
21+
}
22+
23+
apply from: "$rootDir/gradle/java.gradle"
24+
25+
//addTestSuiteForDir('latestDepTest', 'test')
26+
// TODO currently 0.42.56 is the latest version. Enable this once the next (0.42.57) is out, add 'latestDepTest'
27+
28+
dependencies {
29+
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.56'
30+
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.56'
31+
32+
testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.56'
33+
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.56'
34+
35+
// import the previous instrumentation into the test to ensure that it does not interfere with it
36+
testRuntimeOnly project(":dd-java-agent:instrumentation:servicetalk:servicetalk-0.42.0")
37+
38+
// TODO currently 0.42.56 is the latest version. Enable this once the next (0.42.57) is out, add 'latestDepTest'
39+
// latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '+'
40+
// latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '+'
41+
}
42+

0 commit comments

Comments
 (0)