Skip to content

Commit 860baa9

Browse files
make tasks wrapped by grpc-context unwrappable (#6977)
1 parent 20e8b14 commit 860baa9

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import datadog.trace.agent.test.AgentTestRunner
2+
import datadog.trace.bootstrap.instrumentation.api.TaskWrapper
3+
import io.grpc.Context
4+
5+
class UnwrapGrpcContextForkedTest extends AgentTestRunner {
6+
@Override
7+
protected void configurePreAgent() {
8+
super.configurePreAgent()
9+
injectSysConfig("dd.profiling.enabled", "true")
10+
}
11+
12+
def "test unwrap gRPC context wrappers"() {
13+
// relies on TaskUnwrappingInstrumentation (java-concurrent) targeting grpc context
14+
setup:
15+
def runnable = {}
16+
def callable = {"result"}
17+
when:
18+
def unwrappedRunnableType = TaskWrapper.getUnwrappedType(Context.ROOT.wrap(runnable))
19+
then:
20+
unwrappedRunnableType == runnable.getClass()
21+
when:
22+
def unwrappedCallableType = TaskWrapper.getUnwrappedType(Context.ROOT.wrap(callable))
23+
then:
24+
unwrappedCallableType == callable.getClass()
25+
}
26+
}

dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/TaskUnwrappingInstrumentation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public boolean isEnabled() {
5252
"task",
5353
"io.grpc.netty.shaded.io.netty.util.concurrent.PromiseTask",
5454
"task",
55+
"io.grpc.Context$1",
56+
"val$r",
57+
"io.grpc.Context$2",
58+
"val$c",
5559
"akka.dispatch.TaskInvocation",
5660
"runnable",
5761
"scala.concurrent.impl.CallbackRunnable",

0 commit comments

Comments
 (0)