Fix ktor3 latest dep test (#12937)
This commit is contained in:
parent
fa32671be5
commit
de6e0ef675
|
@ -10,6 +10,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
import io.ktor.server.application.Application;
|
import io.ktor.server.application.Application;
|
||||||
import io.ktor.server.application.ApplicationPluginKt;
|
import io.ktor.server.application.ApplicationPluginKt;
|
||||||
|
import io.ktor.server.engine.EmbeddedServer;
|
||||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||||
import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder;
|
import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder;
|
||||||
import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil;
|
import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil;
|
||||||
|
@ -17,6 +18,8 @@ import io.opentelemetry.instrumentation.ktor.v3_0.KtorServerTelemetryBuilderKt;
|
||||||
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
|
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
@ -39,7 +42,18 @@ public class ServerInstrumentation implements TypeInstrumentation {
|
||||||
public static class ConstructorAdvice {
|
public static class ConstructorAdvice {
|
||||||
|
|
||||||
@Advice.OnMethodExit
|
@Advice.OnMethodExit
|
||||||
public static void onExit(@Advice.FieldValue("_applicationInstance") Application application) {
|
public static void onExit(
|
||||||
|
@Advice.This EmbeddedServer<?, ?> server, @Advice.Origin MethodHandles.Lookup lookup)
|
||||||
|
throws Throwable {
|
||||||
|
MethodHandle getter;
|
||||||
|
try {
|
||||||
|
// since 3.0.3
|
||||||
|
getter = lookup.findGetter(EmbeddedServer.class, "applicationInstance", Application.class);
|
||||||
|
} catch (NoSuchFieldException exception) {
|
||||||
|
// before 3.0.3
|
||||||
|
getter = lookup.findGetter(EmbeddedServer.class, "_applicationInstance", Application.class);
|
||||||
|
}
|
||||||
|
Application application = (Application) getter.invoke(server);
|
||||||
ApplicationPluginKt.install(
|
ApplicationPluginKt.install(
|
||||||
application, KtorServerTelemetryBuilderKt.getKtorServerTelemetry(), new SetupFunction());
|
application, KtorServerTelemetryBuilderKt.getKtorServerTelemetry(), new SetupFunction());
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ class AdviceSignatureEraser {
|
||||||
String reference = matcher.group();
|
String reference = matcher.group();
|
||||||
if (reference.startsWith("Ljava/")) {
|
if (reference.startsWith("Ljava/")) {
|
||||||
// do not erase java.* references
|
// do not erase java.* references
|
||||||
matcher.appendReplacement(result, reference);
|
matcher.appendReplacement(result, Matcher.quoteReplacement(reference));
|
||||||
} else {
|
} else {
|
||||||
matcher.appendReplacement(result, "Ljava/lang/Object;");
|
matcher.appendReplacement(result, "Ljava/lang/Object;");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue