Skip to content

Commit 851cfb2

Browse files
authored
Fix flaky finagle http client tests (#11400)
1 parent bfb1a64 commit 851cfb2

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

instrumentation/finagle-http-23.11/javaagent/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ val scalified = fun(pack: String): String {
3030
}
3131

3232
dependencies {
33+
bootstrap(project(":instrumentation:executors:bootstrap"))
34+
3335
library("${scalified("com.twitter:finagle-http")}:$finagleVersion")
3436

3537
// should wire netty contexts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.finaglehttp.v23_11;
7+
8+
import static net.bytebuddy.matcher.ElementMatchers.named;
9+
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
10+
11+
import io.opentelemetry.context.Context;
12+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
13+
import io.opentelemetry.javaagent.bootstrap.executors.ContextPropagatingRunnable;
14+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
15+
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
16+
import net.bytebuddy.asm.Advice;
17+
import net.bytebuddy.description.type.TypeDescription;
18+
import net.bytebuddy.matcher.ElementMatcher;
19+
20+
public class LocalSchedulerActivationInstrumentation implements TypeInstrumentation {
21+
22+
@Override
23+
public ElementMatcher<TypeDescription> typeMatcher() {
24+
return named("com.twitter.concurrent.LocalScheduler$Activation");
25+
}
26+
27+
@Override
28+
public void transform(TypeTransformer transformer) {
29+
transformer.applyAdviceToMethod(
30+
named("submit").and(takesArguments(Runnable.class)),
31+
this.getClass().getName() + "$WrapRunnableAdvice");
32+
}
33+
34+
@SuppressWarnings("unused")
35+
public static class WrapRunnableAdvice {
36+
37+
@Advice.OnMethodEnter(suppress = Throwable.class)
38+
public static void wrap(@Advice.Argument(value = 0, readOnly = false) Runnable task) {
39+
if (task == null) {
40+
return;
41+
}
42+
43+
Context context = Java8BytecodeBridge.currentContext();
44+
task = ContextPropagatingRunnable.propagateContext(task, context);
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.finaglehttp.v23_11;
7+
8+
import static java.util.Collections.singletonList;
9+
10+
import com.google.auto.service.AutoService;
11+
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
12+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
13+
import java.util.List;
14+
15+
@AutoService(InstrumentationModule.class)
16+
public class TwitterUtilCoreInstrumentationModule extends InstrumentationModule {
17+
18+
public TwitterUtilCoreInstrumentationModule() {
19+
super("twitter-util-core");
20+
}
21+
22+
@Override
23+
public List<TypeInstrumentation> typeInstrumentations() {
24+
return singletonList(new LocalSchedulerActivationInstrumentation());
25+
}
26+
}

0 commit comments

Comments
 (0)