Skip to content

ServiceTalk Captured Context API Instrumentation for v0.42.56+ #8821

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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c789ae5
ServiceTalk async context propagation instrumentation. Support 0.42.56+
ygree Apr 30, 2025
a9729e4
Disable ServiceTalk instrumentation for versions prior to 0.42.56 to …
ygree May 13, 2025
e69bc7d
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 13, 2025
b61a8c2
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 13, 2025
9a61436
Automatically disable the old ServiceTalk instrumentation for version…
ygree May 14, 2025
23b0ecf
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 14, 2025
7494d8c
Use CapturedContextProviders API
ygree May 14, 2025
2ea0cec
Update servicetalk lockfiles
ygree May 14, 2025
344f965
Add captureContext specific test
ygree May 15, 2025
d8ad4d6
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 15, 2025
1960ed1
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 16, 2025
0a56a48
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 20, 2025
c2e9100
fix lockfile for servicetalk instrumentation
ygree May 20, 2025
bcd9c17
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 20, 2025
2d257f6
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 21, 2025
500ddc0
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 21, 2025
c2faa29
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 21, 2025
1172152
Include the other ServiceTalk instruments in the test to make sure th…
ygree May 21, 2025
d007dba
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 21, 2025
9495537
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 22, 2025
e064fd6
Disable latestDepTest for ServiceTalk 0.42.56 because this is the onl…
ygree May 22, 2025
6368011
Fix false positive bug detection
ygree May 22, 2025
ce391d2
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 22, 2025
f7bc934
Fix muzzle check
ygree May 22, 2025
0b6f63a
Fix latestDep tests
ygree May 23, 2025
1de5f85
Update lockfile
ygree May 23, 2025
5c2f307
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentati…
ygree May 23, 2025
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
38 changes: 0 additions & 38 deletions dd-java-agent/instrumentation/servicetalk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
plugins {
id 'java-test-fixtures'
}

muzzle {
pass {
group = 'io.servicetalk'
module = 'servicetalk-concurrent-api'
// prev versions missing ContextMap
versions = '[0.41.12,)'
assertInverse = true
}
pass {
group = 'io.servicetalk'
module = 'servicetalk-context-api'
versions = '[0.1.0,)'
assertInverse = true
}
}

ext {
minJavaVersionForTests = JavaVersion.VERSION_11
}

apply from: "$rootDir/gradle/java.gradle"

addTestSuiteForDir('latestDepTest', 'test')

dependencies {
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.45'
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.45'

testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.0'
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.0'

latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '+'
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '+'
}

264 changes: 119 additions & 145 deletions dd-java-agent/instrumentation/servicetalk/gradle.lockfile

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id 'java-test-fixtures'
}

muzzle {
pass {
group = 'io.servicetalk'
module = 'servicetalk-concurrent-api'
versions = '[0.42.0,0.42.55]'
}
fail {
group = 'io.servicetalk'
module = 'servicetalk-concurrent-api'
versions = '(0.42.55,]'
}
}

ext {
minJavaVersionForTests = JavaVersion.VERSION_11
}

apply from: "$rootDir/gradle/java.gradle"

addTestSuiteForDir('latestDepTest', 'test')

dependencies {
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.0'
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.0'

testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.42'
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.42'

// import the newer instrumentation into the test to ensure that it does not interfere with it
testRuntimeOnly project(":dd-java-agent:instrumentation:servicetalk:servicetalk-0.42.56")

latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.55'
latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.55'
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.trace.instrumentation.servicetalk;
package datadog.trace.instrumentation.servicetalk0_42_0;

import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
Expand All @@ -16,7 +16,7 @@
import net.bytebuddy.asm.Advice;

@AutoService(InstrumenterModule.class)
public class ContextMapInstrumentation extends AbstractAsyncContextInstrumentation
public class ContextMapInstrumentation extends ServiceTalkInstrumentation
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {

@Override
Expand All @@ -40,6 +40,8 @@ public void methodAdvice(MethodTransformer transformer) {
private static final class Construct {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void exit(@Advice.This ContextMap contextMap) {
// Capture an active span on ST context copy to support versions prior to 0.42.56 that did not
// have captureContext
InstrumentationContext.get(ContextMap.class, AgentSpan.class)
.put(contextMap, AgentTracer.activeSpan());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.trace.instrumentation.servicetalk;
package datadog.trace.instrumentation.servicetalk0_42_0;

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

Expand All @@ -13,7 +13,7 @@
import net.bytebuddy.asm.Advice;

@AutoService(InstrumenterModule.class)
public class ContextPreservingInstrumentation extends AbstractAsyncContextInstrumentation
public class ContextPreservingInstrumentation extends ServiceTalkInstrumentation
implements Instrumenter.ForKnownTypes, Instrumenter.HasMethodAdvice {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package datadog.trace.instrumentation.servicetalk0_42_0;

import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.agent.tooling.muzzle.Reference;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import java.util.Collections;
import java.util.Map;

public abstract class ServiceTalkInstrumentation extends InstrumenterModule.Tracing {

public ServiceTalkInstrumentation() {
super("servicetalk", "servicetalk-concurrent");
}

@Override
public Map<String, String> contextStore() {
return Collections.singletonMap(
"io.servicetalk.context.api.ContextMap", AgentSpan.class.getName());
}

@Override
public Reference[] additionalMuzzleReferences() {
return new Reference[] {
// This check prevents older instrumentation from being applied to ServiceTalk v0.42.56+
new Reference.Builder("io.servicetalk.concurrent.api.DelegatingExecutor")
// Removed in v0.42.56
.withField(new String[0], 0, "delegate", "Lio/servicetalk/concurrent/api/Executor;")
.build(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import datadog.trace.bootstrap.instrumentation.api.AgentScope
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
import io.servicetalk.concurrent.api.AsyncContext
import io.servicetalk.context.api.ContextMap

import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

Expand Down Expand Up @@ -150,7 +149,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
}
}

private childSpan() {
private static childSpan() {
AgentTracer.startSpan("test", "child").finish()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java-test-fixtures'
}

muzzle {
fail {
group = 'io.servicetalk'
module = 'servicetalk-concurrent-api'
versions = '[,0.42.56)'
}
pass {
group = 'io.servicetalk'
module = 'servicetalk-concurrent-api'
// 0.42.56 is the earliest version where CapturedContext is public
versions = '[0.42.56,]'
}
}

ext {
minJavaVersionForTests = JavaVersion.VERSION_11
}

apply from: "$rootDir/gradle/java.gradle"

//addTestSuiteForDir('latestDepTest', 'test')
// TODO currently 0.42.56 is the latest version. Enable this once the next (0.42.57) is out, add 'latestDepTest'

dependencies {
compileOnly group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.56'
compileOnly group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.56'

testImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '0.42.56'
testImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '0.42.56'

// import the previous instrumentation into the test to ensure that it does not interfere with it
testRuntimeOnly project(":dd-java-agent:instrumentation:servicetalk:servicetalk-0.42.0")

// TODO currently 0.42.56 is the latest version. Enable this once the next (0.42.57) is out, add 'latestDepTest'
// latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-concurrent-api', version: '+'
// latestDepTestImplementation group: 'io.servicetalk', name: 'servicetalk-context-api', version: '+'
}

Loading
Loading