Skip to content

Commit

Permalink
Fix flaky finagle http client tests (#11400)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored May 20, 2024
1 parent bfb1a64 commit 851cfb2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions instrumentation/finagle-http-23.11/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ val scalified = fun(pack: String): String {
}

dependencies {
bootstrap(project(":instrumentation:executors:bootstrap"))

library("${scalified("com.twitter:finagle-http")}:$finagleVersion")

// should wire netty contexts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.finaglehttp.v23_11;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.bootstrap.executors.ContextPropagatingRunnable;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class LocalSchedulerActivationInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("com.twitter.concurrent.LocalScheduler$Activation");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("submit").and(takesArguments(Runnable.class)),
this.getClass().getName() + "$WrapRunnableAdvice");
}

@SuppressWarnings("unused")
public static class WrapRunnableAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrap(@Advice.Argument(value = 0, readOnly = false) Runnable task) {
if (task == null) {
return;
}

Context context = Java8BytecodeBridge.currentContext();
task = ContextPropagatingRunnable.propagateContext(task, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.finaglehttp.v23_11;

import static java.util.Collections.singletonList;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class TwitterUtilCoreInstrumentationModule extends InstrumentationModule {

public TwitterUtilCoreInstrumentationModule() {
super("twitter-util-core");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new LocalSchedulerActivationInstrumentation());
}
}

0 comments on commit 851cfb2

Please sign in to comment.