Skip to content
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

Add Ktor 3.0.0 support #12453

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
package io.opentelemetry.javaagent.instrumentation.ktor.v2_0;

import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;

import io.ktor.server.application.Application;
import io.ktor.server.application.ApplicationPluginKt;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.ktor.v2_0.internal.KtorBuilderUtil;
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing;
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracingBuilder;
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracingKt;
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
Expand All @@ -25,7 +26,10 @@
public class ServerInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("io.ktor.server.engine.ApplicationEngineEnvironmentReloading");
return namedOneOf(
"io.ktor.server.engine.ApplicationEngineEnvironmentReloading", // Ktor 2.0
"io.ktor.server.engine.EmbeddedServer" // Ktor 3.0
);
}

@Override
Expand All @@ -39,15 +43,15 @@ public static class ConstructorAdvice {

@Advice.OnMethodExit
public static void onExit(@Advice.FieldValue("_applicationInstance") Application application) {
ApplicationPluginKt.install(application, KtorServerTracing.Feature, new SetupFunction());
ApplicationPluginKt.install(
application, KtorServerTracingKt.getKtorServerTracing(), new SetupFunction());
}
}

public static class SetupFunction
implements Function1<KtorServerTracing.Configuration, kotlin.Unit> {
public static class SetupFunction implements Function1<KtorServerTracingBuilder, kotlin.Unit> {

@Override
public Unit invoke(KtorServerTracing.Configuration configuration) {
public Unit invoke(KtorServerTracingBuilder configuration) {
configuration.setOpenTelemetry(GlobalOpenTelemetry.get());
KtorBuilderUtil.serverBuilderExtractor
.invoke(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import io.ktor.server.response.*
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder
import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracingBuilder

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
object KtorBuilderUtil {
lateinit var clientBuilderExtractor: (KtorClientTracingBuilder) -> DefaultHttpClientInstrumenterBuilder<HttpRequestData, HttpResponse>
lateinit var serverBuilderExtractor: (KtorServerTracing.Configuration) -> DefaultHttpServerInstrumenterBuilder<ApplicationRequest, ApplicationResponse>
lateinit var serverBuilderExtractor: (KtorServerTracingBuilder) -> DefaultHttpServerInstrumenterBuilder<ApplicationRequest, ApplicationResponse>
}
Loading
Loading