From 1381b65772ba72b77ef7dfe120759b0c8ae604af Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 10 Nov 2021 16:16:41 +0200 Subject: [PATCH 1/5] Trace DNS resolution in reactor-netty --- .../javaagent/build.gradle.kts | 9 ++ .../netty/v4_1/AttributeKeys.java | 2 +- .../InstrumentedAddressResolverGroup.java | 6 +- .../netty-4.1/javaagent/build.gradle.kts | 3 +- ...tChannelHandlerContextInstrumentation.java | 1 - .../netty/v4_1/BootstrapInstrumentation.java | 2 - .../netty/v4_1/ChannelInstrumentation.java | 1 - .../HttpClientRequestTracingHandler.java | 2 +- .../HttpClientResponseTracingHandler.java | 2 +- .../HttpServerRequestTracingHandler.java | 2 +- .../HttpServerResponseTracingHandler.java | 2 +- .../netty/netty-4.1/library/build.gradle.kts | 7 -- .../javaagent/build.gradle.kts | 2 +- .../reactornetty/v0_9/DecoratorFunctions.java | 2 +- .../reactornetty/v0_9/OnRequest.java | 2 +- .../javaagent/build.gradle.kts | 6 +- .../v1_0/ConnectionRequestAndContext.java | 23 +++++ .../reactornetty/v1_0/ConnectionWrapper.java | 41 ++++++-- .../reactornetty/v1_0/DecoratorFunctions.java | 2 +- .../reactornetty/v1_0/OnRequest.java | 2 +- .../TransportConnectorInstrumentation.java | 95 ++++++++++++++++++- .../ReactorNettyConnectionSpanTest.groovy | 30 +++++- settings.gradle.kts | 2 +- 23 files changed, 199 insertions(+), 47 deletions(-) create mode 100644 instrumentation/netty/netty-4.1-common/javaagent/build.gradle.kts rename instrumentation/netty/{netty-4.1/library/src/main/java/io/opentelemetry => netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent}/instrumentation/netty/v4_1/AttributeKeys.java (93%) rename instrumentation/netty/{netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client => netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1}/InstrumentedAddressResolverGroup.java (93%) delete mode 100644 instrumentation/netty/netty-4.1/library/build.gradle.kts create mode 100644 instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionRequestAndContext.java diff --git a/instrumentation/netty/netty-4.1-common/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1-common/javaagent/build.gradle.kts new file mode 100644 index 000000000000..370c74a584e1 --- /dev/null +++ b/instrumentation/netty/netty-4.1-common/javaagent/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("otel.javaagent-instrumentation") +} + +dependencies { + api(project(":instrumentation:netty:netty-4-common:javaagent")) + + compileOnly("io.netty:netty-codec-http:4.1.0.Final") +} diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AttributeKeys.java b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java similarity index 93% rename from instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AttributeKeys.java rename to instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java index 068548dc6dc8..307b8e1cc172 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AttributeKeys.java +++ b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.netty.v4_1; +package io.opentelemetry.javaagent.instrumentation.netty.v4_1; import io.netty.util.AttributeKey; import io.opentelemetry.context.Context; diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java similarity index 93% rename from instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java rename to instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java index 1cb5438229d1..3607fce2e83d 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java +++ b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java @@ -3,9 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.netty.v4_1.client; - -import static io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.NettyClientSingletons.connectionInstrumenter; +package io.opentelemetry.javaagent.instrumentation.netty.v4_1; import io.netty.resolver.AddressResolver; import io.netty.resolver.AddressResolverGroup; @@ -27,7 +25,7 @@ public static AddressResolverGroup wrap( if (delegate instanceof InstrumentedAddressResolverGroup) { return delegate; } - return new InstrumentedAddressResolverGroup<>(connectionInstrumenter(), delegate); + return new InstrumentedAddressResolverGroup<>(instrumenter, delegate); } private final NettyConnectionInstrumenter instrumenter; diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index 8ebea2fd4753..038984b59271 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -25,8 +25,7 @@ muzzle { dependencies { library("io.netty:netty-codec-http:4.1.0.Final") - api(project(":instrumentation:netty:netty-4.1:library")) - implementation(project(":instrumentation:netty:netty-4-common:javaagent")) + implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) // Contains logging handler testLibrary("io.netty:netty-handler:4.1.0.Final") diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AbstractChannelHandlerContextInstrumentation.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AbstractChannelHandlerContextInstrumentation.java index 5c6ba09a9796..717f3d7a59fb 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AbstractChannelHandlerContextInstrumentation.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AbstractChannelHandlerContextInstrumentation.java @@ -13,7 +13,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.util.Attribute; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java index aa9529a9d0ee..e50432827e4a 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java @@ -22,7 +22,6 @@ import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; import io.opentelemetry.javaagent.instrumentation.netty.common.client.ConnectionCompleteListener; -import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup; import java.net.SocketAddress; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -84,7 +83,6 @@ public static void startConnect( Context parentContext = Java8BytecodeBridge.currentContext(); request = NettyConnectionRequest.connect(remoteAddress); - if (!connectionInstrumenter().shouldStart(parentContext, request)) { return; } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/ChannelInstrumentation.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/ChannelInstrumentation.java index e2e3779bb560..783e6c8a4a37 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/ChannelInstrumentation.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/ChannelInstrumentation.java @@ -12,7 +12,6 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; import io.netty.channel.Channel; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientRequestTracingHandler.java index fb1a496aafe5..3e6e52a0834d 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientRequestTracingHandler.java @@ -15,8 +15,8 @@ import io.netty.util.Attribute; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; public class HttpClientRequestTracingHandler extends ChannelOutboundHandlerAdapter { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientResponseTracingHandler.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientResponseTracingHandler.java index 993f6486e563..9ba33c96a835 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientResponseTracingHandler.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/HttpClientResponseTracingHandler.java @@ -16,8 +16,8 @@ import io.netty.util.Attribute; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; public class HttpClientResponseTracingHandler extends ChannelInboundHandlerAdapter { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerRequestTracingHandler.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerRequestTracingHandler.java index a3e511f9c926..61fd8064b859 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerRequestTracingHandler.java @@ -14,8 +14,8 @@ import io.netty.util.Attribute; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java index 6646f08f4d00..fa47319f409e 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java @@ -18,9 +18,9 @@ import io.netty.util.Attribute; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import javax.annotation.Nullable; public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter { diff --git a/instrumentation/netty/netty-4.1/library/build.gradle.kts b/instrumentation/netty/netty-4.1/library/build.gradle.kts deleted file mode 100644 index efd05fe21d21..000000000000 --- a/instrumentation/netty/netty-4.1/library/build.gradle.kts +++ /dev/null @@ -1,7 +0,0 @@ -plugins { - id("otel.library-instrumentation") -} - -dependencies { - compileOnly("io.netty:netty-codec-http:4.1.0.Final") -} diff --git a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts index 218099bca3a4..b3bf76977779 100644 --- a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts @@ -16,7 +16,7 @@ muzzle { } dependencies { - implementation(project(":instrumentation:netty:netty-4.1:library")) + implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) library("io.projectreactor.netty:reactor-netty:0.9.0.RELEASE") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-1.0:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/DecoratorFunctions.java b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/DecoratorFunctions.java index ad167fb644d4..984e167e4cc3 100644 --- a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/DecoratorFunctions.java +++ b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/DecoratorFunctions.java @@ -8,7 +8,7 @@ import io.netty.channel.Channel; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import java.util.function.BiConsumer; import javax.annotation.Nullable; import reactor.netty.Connection; diff --git a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/OnRequest.java b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/OnRequest.java index 706f01be62f8..032eba29ba66 100644 --- a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/OnRequest.java +++ b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/OnRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.reactornetty.v0_9; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import java.util.function.BiConsumer; import reactor.netty.Connection; import reactor.netty.http.client.HttpClientRequest; diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts index f85f9744e08e..32626ab04d98 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts @@ -17,8 +17,10 @@ muzzle { } dependencies { - implementation(project(":instrumentation:netty:netty-4.1:library")) - implementation(project(":instrumentation:netty:netty-4-common:javaagent")) + compileOnly("com.google.auto.value:auto-value-annotations") + annotationProcessor("com.google.auto.value:auto-value") + + implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) library("io.projectreactor.netty:reactor-netty-http:1.0.0") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-0.9:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionRequestAndContext.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionRequestAndContext.java new file mode 100644 index 000000000000..3d6b63d3e139 --- /dev/null +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionRequestAndContext.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0; + +import com.google.auto.value.AutoValue; +import io.opentelemetry.context.Context; +import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; + +@AutoValue +public abstract class ConnectionRequestAndContext { + + public static ConnectionRequestAndContext create( + NettyConnectionRequest request, Context context) { + return new AutoValue_ConnectionRequestAndContext(request, context); + } + + public abstract NettyConnectionRequest request(); + + public abstract Context context(); +} diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java index d68f777cb65c..43e206a9aaee 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java @@ -8,15 +8,42 @@ import static io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0.ReactorNettySingletons.connectionInstrumenter; import io.netty.channel.Channel; -import io.opentelemetry.context.Context; -import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; +import io.netty.channel.ChannelPromise; +import io.opentelemetry.instrumentation.api.field.VirtualField; import reactor.core.publisher.Mono; -public class ConnectionWrapper { +public final class ConnectionWrapper { - public static Mono wrap( - Context context, NettyConnectionRequest request, Mono mono) { - return mono.doOnError(error -> connectionInstrumenter().end(context, request, null, error)) - .doOnSuccess(channel -> connectionInstrumenter().end(context, request, channel, null)); + private static final VirtualField + requestAndContextField = + VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class); + + public static Mono wrap(Mono mono) { + // if we didn't attach the connection context&request then we have nothing to instrument + if (!(mono instanceof ChannelPromise)) { + return mono; + } + return mono.doOnError( + error -> { + ConnectionRequestAndContext requestAndContext = + requestAndContextField.get((ChannelPromise) mono); + if (requestAndContext == null) { + return; + } + connectionInstrumenter() + .end(requestAndContext.context(), requestAndContext.request(), null, error); + }) + .doOnSuccess( + channel -> { + ConnectionRequestAndContext requestAndContext = + requestAndContextField.get((ChannelPromise) mono); + if (requestAndContext == null) { + return; + } + connectionInstrumenter() + .end(requestAndContext.context(), requestAndContext.request(), channel, null); + }); } + + private ConnectionWrapper() {} } diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/DecoratorFunctions.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/DecoratorFunctions.java index 85a7749ccfec..d53a719f70da 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/DecoratorFunctions.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/DecoratorFunctions.java @@ -8,7 +8,7 @@ import io.netty.channel.Channel; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import java.util.function.BiConsumer; import javax.annotation.Nullable; import reactor.netty.Connection; diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/OnRequest.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/OnRequest.java index adff05db756b..709d4d445d44 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/OnRequest.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/OnRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import java.util.function.BiConsumer; import reactor.netty.Connection; import reactor.netty.http.client.HttpClientRequest; diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java index 527ec8530750..510c528cfe6e 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java @@ -7,22 +7,29 @@ import static io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0.ReactorNettySingletons.connectionInstrumenter; import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.returns; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.netty.channel.Channel; +import io.netty.channel.ChannelPromise; +import io.netty.resolver.AddressResolverGroup; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; +import io.opentelemetry.instrumentation.api.field.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.InstrumentedAddressResolverGroup; import java.net.SocketAddress; +import java.util.List; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; import reactor.core.publisher.Mono; public class TransportConnectorInstrumentation implements TypeInstrumentation { + @Override public ElementMatcher typeMatcher() { return named("reactor.netty.transport.TransportConnector"); @@ -31,15 +38,48 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - named("connect").and(takesArgument(1, named("java.net.SocketAddress"))), + named("doResolveAndConnect") + .and(takesArgument(3, named("io.netty.resolver.AddressResolverGroup"))) + .and(returns(named("reactor.core.publisher.Mono"))), + TransportConnectorInstrumentation.class.getName() + "$ResolveAndConnectAdvice"); + + // handles [1.0.0, 1.0.6) + transformer.applyAdviceToMethod( + named("doConnect") + .and(takesArgument(0, SocketAddress.class)) + .and(takesArgument(2, named("io.netty.channel.ChannelPromise"))), TransportConnectorInstrumentation.class.getName() + "$ConnectAdvice"); + // handles [1.0.6, ) + transformer.applyAdviceToMethod( + named("doConnect") + .and(takesArgument(0, List.class)) + .and(takesArgument(2, named("io.netty.channel.ChannelPromise"))) + .and(takesArgument(3, int.class)), + TransportConnectorInstrumentation.class.getName() + "$ConnectNewAdvice"); + } + + @SuppressWarnings("unused") + public static class ResolveAndConnectAdvice { + + @Advice.OnMethodEnter(suppress = Throwable.class) + public static void onEnter( + @Advice.Argument(value = 3, readOnly = false) AddressResolverGroup resolver) { + resolver = InstrumentedAddressResolverGroup.wrap(connectionInstrumenter(), resolver); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void onExit(@Advice.Return(readOnly = false) Mono mono) { + // end the CONNECT span inside the wrapped mono + mono = ConnectionWrapper.wrap(mono); + } } + @SuppressWarnings("unused") public static class ConnectAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static void startConnect( - @Advice.Argument(1) SocketAddress remoteAddress, + public static void onEnter( + @Advice.Argument(0) SocketAddress remoteAddress, @Advice.Local("otelContext") Context context, @Advice.Local("otelRequest") NettyConnectionRequest request, @Advice.Local("otelScope") Scope scope) { @@ -57,7 +97,50 @@ public static void startConnect( @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void endConnect( @Advice.Thrown Throwable throwable, - @Advice.Return(readOnly = false) Mono mono, + @Advice.Argument(2) ChannelPromise channelPromise, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelRequest") NettyConnectionRequest request, + @Advice.Local("otelScope") Scope scope) { + + if (scope != null) { + scope.close(); + } + + if (throwable != null) { + connectionInstrumenter().end(context, request, null, throwable); + } else { + // the span is finished in the mono decorated by the ConnectionWrapper + VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class) + .set(channelPromise, ConnectionRequestAndContext.create(request, context)); + } + } + } + + @SuppressWarnings("unused") + public static class ConnectNewAdvice { + + @Advice.OnMethodEnter(suppress = Throwable.class) + public static void onEnter( + @Advice.Argument(0) List remoteAddresses, + @Advice.Argument(3) int index, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelRequest") NettyConnectionRequest request, + @Advice.Local("otelScope") Scope scope) { + + Context parentContext = Java8BytecodeBridge.currentContext(); + request = NettyConnectionRequest.connect(remoteAddresses.get(index)); + if (!connectionInstrumenter().shouldStart(parentContext, request)) { + return; + } + + context = connectionInstrumenter().start(parentContext, request); + scope = context.makeCurrent(); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void endConnect( + @Advice.Thrown Throwable throwable, + @Advice.Argument(2) ChannelPromise channelPromise, @Advice.Local("otelContext") Context context, @Advice.Local("otelRequest") NettyConnectionRequest request, @Advice.Local("otelScope") Scope scope) { @@ -69,7 +152,9 @@ public static void endConnect( if (throwable != null) { connectionInstrumenter().end(context, request, null, throwable); } else { - mono = ConnectionWrapper.wrap(context, request, mono); + // the span is finished in the mono decorated by the ConnectionWrapper + VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class) + .set(channelPromise, ConnectionRequestAndContext.create(request, context)); } } } diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.groovy b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.groovy index 4e1edba4e6c9..4484351b6105 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.groovy +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.groovy @@ -50,13 +50,23 @@ class ReactorNettyConnectionSpanTest extends InstrumentationSpecification implem then: responseCode == 200 assertTraces(1) { - trace(0, 4) { + trace(0, 5) { span(0) { name "parent" kind INTERNAL hasNoParent() } span(1) { + name "RESOLVE" + kind INTERNAL + childOf span(0) + attributes { + "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP + "${SemanticAttributes.NET_PEER_NAME.key}" "localhost" + "${SemanticAttributes.NET_PEER_PORT.key}" server.httpPort() + } + } + span(2) { name "CONNECT" kind INTERNAL childOf(span(0)) @@ -67,15 +77,15 @@ class ReactorNettyConnectionSpanTest extends InstrumentationSpecification implem "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" } } - span(2) { + span(3) { name "HTTP GET" kind CLIENT childOf(span(0)) } - span(3) { + span(4) { name "test-http-server" kind SERVER - childOf(span(2)) + childOf(span(3)) } } } @@ -100,7 +110,7 @@ class ReactorNettyConnectionSpanTest extends InstrumentationSpecification implem and: assertTraces(1) { - trace(0, 2) { + trace(0, 3) { span(0) { name "parent" kind INTERNAL @@ -109,6 +119,16 @@ class ReactorNettyConnectionSpanTest extends InstrumentationSpecification implem errorEvent(thrownException.class, thrownException.message) } span(1) { + name "RESOLVE" + kind INTERNAL + childOf span(0) + attributes { + "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP + "${SemanticAttributes.NET_PEER_NAME.key}" "localhost" + "${SemanticAttributes.NET_PEER_PORT.key}" PortUtils.UNUSABLE_PORT + } + } + span(2) { name "CONNECT" kind INTERNAL childOf(span(0)) diff --git a/settings.gradle.kts b/settings.gradle.kts index 082f3a7fe7b6..8344ef85ce24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -255,8 +255,8 @@ include(":instrumentation:mongo:mongo-async-3.3:javaagent") include(":instrumentation:mongo:mongo-common:testing") include(":instrumentation:netty:netty-3.8:javaagent") include(":instrumentation:netty:netty-4.0:javaagent") -include(":instrumentation:netty:netty-4.1:library") include(":instrumentation:netty:netty-4.1:javaagent") +include(":instrumentation:netty:netty-4.1-common:javaagent") include(":instrumentation:netty:netty-4-common:javaagent") include(":instrumentation:netty:netty-common:javaagent") include(":instrumentation:okhttp:okhttp-2.2:javaagent") From ac823866500503b04aac1b9d4c29b718c801a3bc Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Thu, 11 Nov 2021 10:49:15 +0200 Subject: [PATCH 2/5] Code review comments --- .../netty-4.1/javaagent/build.gradle.kts | 1 - .../netty/v4_1/AttributeKeys.java | 0 .../netty/v4_1/BootstrapInstrumentation.java | 1 + .../InstrumentedAddressResolverGroup.java | 2 +- .../ratpack/TracingHandler.java | 2 +- .../javaagent/build.gradle.kts | 2 +- .../javaagent/build.gradle.kts | 2 +- .../reactornetty/v1_0/ConnectionWrapper.java | 35 ++++++++----------- .../TransportConnectorInstrumentation.java | 4 +-- settings.gradle.kts | 1 - 10 files changed, 22 insertions(+), 28 deletions(-) rename instrumentation/netty/{netty-4.1-common => netty-4.1}/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java (100%) rename instrumentation/netty/{netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1 => netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client}/InstrumentedAddressResolverGroup.java (98%) diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index 038984b59271..64e1c77ca2c9 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -25,7 +25,6 @@ muzzle { dependencies { library("io.netty:netty-codec-http:4.1.0.Final") - implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) // Contains logging handler testLibrary("io.netty:netty-handler:4.1.0.Final") diff --git a/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java similarity index 100% rename from instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java rename to instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java index e50432827e4a..708302cfbd52 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java @@ -22,6 +22,7 @@ import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; import io.opentelemetry.javaagent.instrumentation.netty.common.client.ConnectionCompleteListener; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup; import java.net.SocketAddress; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; diff --git a/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java similarity index 98% rename from instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java rename to instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java index 3607fce2e83d..e6751c982d26 100644 --- a/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.netty.v4_1; +package io.opentelemetry.javaagent.instrumentation.netty.v4_1.client; import io.netty.resolver.AddressResolver; import io.netty.resolver.AddressResolverGroup; diff --git a/instrumentation/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/TracingHandler.java b/instrumentation/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/TracingHandler.java index 417455b4e0d2..e8178b1f2b15 100644 --- a/instrumentation/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/TracingHandler.java +++ b/instrumentation/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/TracingHandler.java @@ -11,8 +11,8 @@ import io.netty.util.Attribute; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys; import ratpack.handling.Context; import ratpack.handling.Handler; diff --git a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts index b3bf76977779..bbd3c6d7b9d5 100644 --- a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts @@ -16,7 +16,7 @@ muzzle { } dependencies { - implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) + implementation(project(":instrumentation:netty:netty-4.1:javaagent")) library("io.projectreactor.netty:reactor-netty:0.9.0.RELEASE") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-1.0:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts index 32626ab04d98..64bb8f5237db 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) + implementation(project(":instrumentation:netty:netty-4.1:javaagent")) library("io.projectreactor.netty:reactor-netty-http:1.0.0") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-0.9:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java index 43e206a9aaee..2a4527835926 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ConnectionWrapper.java @@ -10,6 +10,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelPromise; import io.opentelemetry.instrumentation.api.field.VirtualField; +import javax.annotation.Nullable; import reactor.core.publisher.Mono; public final class ConnectionWrapper { @@ -23,26 +24,20 @@ public static Mono wrap(Mono mono) { if (!(mono instanceof ChannelPromise)) { return mono; } - return mono.doOnError( - error -> { - ConnectionRequestAndContext requestAndContext = - requestAndContextField.get((ChannelPromise) mono); - if (requestAndContext == null) { - return; - } - connectionInstrumenter() - .end(requestAndContext.context(), requestAndContext.request(), null, error); - }) - .doOnSuccess( - channel -> { - ConnectionRequestAndContext requestAndContext = - requestAndContextField.get((ChannelPromise) mono); - if (requestAndContext == null) { - return; - } - connectionInstrumenter() - .end(requestAndContext.context(), requestAndContext.request(), channel, null); - }); + return mono.doOnError(error -> end(mono, null, error)) + .doOnSuccess(channel -> end(mono, channel, null)) + .doOnCancel(() -> end(mono, null, null)); + } + + private static void end( + Mono mono, @Nullable Channel channel, @Nullable Throwable error) { + ConnectionRequestAndContext requestAndContext = + requestAndContextField.get((ChannelPromise) mono); + if (requestAndContext == null) { + return; + } + connectionInstrumenter() + .end(requestAndContext.context(), requestAndContext.request(), channel, error); } private ConnectionWrapper() {} diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java index 510c528cfe6e..20d09cfcb584 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java @@ -20,7 +20,7 @@ import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; -import io.opentelemetry.javaagent.instrumentation.netty.v4_1.InstrumentedAddressResolverGroup; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup; import java.net.SocketAddress; import java.util.List; import net.bytebuddy.asm.Advice; @@ -69,7 +69,7 @@ public static void onEnter( @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit(@Advice.Return(readOnly = false) Mono mono) { - // end the CONNECT span inside the wrapped mono + // end the CONNECT span that was started in doConnect() instrumentation mono = ConnectionWrapper.wrap(mono); } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 8344ef85ce24..288a4641d2b5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -256,7 +256,6 @@ include(":instrumentation:mongo:mongo-common:testing") include(":instrumentation:netty:netty-3.8:javaagent") include(":instrumentation:netty:netty-4.0:javaagent") include(":instrumentation:netty:netty-4.1:javaagent") -include(":instrumentation:netty:netty-4.1-common:javaagent") include(":instrumentation:netty:netty-4-common:javaagent") include(":instrumentation:netty:netty-common:javaagent") include(":instrumentation:okhttp:okhttp-2.2:javaagent") From 31bd286777618a3d664d7c971287a4a077364e1c Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Thu, 11 Nov 2021 11:02:40 +0200 Subject: [PATCH 3/5] removed a little too much --- instrumentation/netty/netty-4.1/javaagent/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index 64e1c77ca2c9..bab0a85f43ae 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -25,6 +25,7 @@ muzzle { dependencies { library("io.netty:netty-codec-http:4.1.0.Final") + implementation(project(":instrumentation:netty:netty-4-common:javaagent")) // Contains logging handler testLibrary("io.netty:netty-handler:4.1.0.Final") From 18c0a7290cb323f89c037ccd2d734e1439737c7d Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Thu, 11 Nov 2021 11:23:11 +0200 Subject: [PATCH 4/5] implementation -> api --- instrumentation/netty/netty-4.1/javaagent/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index bab0a85f43ae..3612f871c4ec 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -25,7 +25,7 @@ muzzle { dependencies { library("io.netty:netty-codec-http:4.1.0.Final") - implementation(project(":instrumentation:netty:netty-4-common:javaagent")) + api(project(":instrumentation:netty:netty-4-common:javaagent")) // Contains logging handler testLibrary("io.netty:netty-handler:4.1.0.Final") From fefdf03a57c0c8d4508ca3cd3e544614a8fb641a Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Thu, 11 Nov 2021 13:55:02 +0200 Subject: [PATCH 5/5] revert and make muzzle happy --- .../instrumentation/netty/v4_1/AttributeKeys.java | 0 .../v4_1}/InstrumentedAddressResolverGroup.java | 2 +- .../netty/netty-4.1/javaagent/build.gradle.kts | 2 +- .../netty/v4_1/BootstrapInstrumentation.java | 1 - .../reactor-netty-0.9/javaagent/build.gradle.kts | 2 +- .../reactor-netty-1.0/javaagent/build.gradle.kts | 2 +- .../v1_0/TransportConnectorInstrumentation.java | 12 +++++++----- settings.gradle.kts | 1 + 8 files changed, 12 insertions(+), 10 deletions(-) rename instrumentation/netty/{netty-4.1 => netty-4.1-common}/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java (100%) rename instrumentation/netty/{netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client => netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1}/InstrumentedAddressResolverGroup.java (98%) diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java similarity index 100% rename from instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java rename to instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/AttributeKeys.java diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java similarity index 98% rename from instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java rename to instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java index e6751c982d26..3607fce2e83d 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/client/InstrumentedAddressResolverGroup.java +++ b/instrumentation/netty/netty-4.1-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/InstrumentedAddressResolverGroup.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.netty.v4_1.client; +package io.opentelemetry.javaagent.instrumentation.netty.v4_1; import io.netty.resolver.AddressResolver; import io.netty.resolver.AddressResolverGroup; diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index 3612f871c4ec..93de90e3d35a 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -25,7 +25,7 @@ muzzle { dependencies { library("io.netty:netty-codec-http:4.1.0.Final") - api(project(":instrumentation:netty:netty-4-common:javaagent")) + api(project(":instrumentation:netty:netty-4.1-common:javaagent")) // Contains logging handler testLibrary("io.netty:netty-handler:4.1.0.Final") diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java index 708302cfbd52..e50432827e4a 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/BootstrapInstrumentation.java @@ -22,7 +22,6 @@ import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; import io.opentelemetry.javaagent.instrumentation.netty.common.client.ConnectionCompleteListener; -import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup; import java.net.SocketAddress; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; diff --git a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts index bbd3c6d7b9d5..b3bf76977779 100644 --- a/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-0.9/javaagent/build.gradle.kts @@ -16,7 +16,7 @@ muzzle { } dependencies { - implementation(project(":instrumentation:netty:netty-4.1:javaagent")) + implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) library("io.projectreactor.netty:reactor-netty:0.9.0.RELEASE") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-1.0:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts index 64bb8f5237db..32626ab04d98 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - implementation(project(":instrumentation:netty:netty-4.1:javaagent")) + implementation(project(":instrumentation:netty:netty-4.1-common:javaagent")) library("io.projectreactor.netty:reactor-netty-http:1.0.0") testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-0.9:javaagent")) diff --git a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java index 20d09cfcb584..c2e8f682eef2 100644 --- a/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java +++ b/instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java @@ -20,7 +20,7 @@ import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest; -import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup; +import io.opentelemetry.javaagent.instrumentation.netty.v4_1.InstrumentedAddressResolverGroup; import java.net.SocketAddress; import java.util.List; import net.bytebuddy.asm.Advice; @@ -102,9 +102,10 @@ public static void endConnect( @Advice.Local("otelRequest") NettyConnectionRequest request, @Advice.Local("otelScope") Scope scope) { - if (scope != null) { - scope.close(); + if (scope == null) { + return; } + scope.close(); if (throwable != null) { connectionInstrumenter().end(context, request, null, throwable); @@ -145,9 +146,10 @@ public static void endConnect( @Advice.Local("otelRequest") NettyConnectionRequest request, @Advice.Local("otelScope") Scope scope) { - if (scope != null) { - scope.close(); + if (scope == null) { + return; } + scope.close(); if (throwable != null) { connectionInstrumenter().end(context, request, null, throwable); diff --git a/settings.gradle.kts b/settings.gradle.kts index 288a4641d2b5..8344ef85ce24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -256,6 +256,7 @@ include(":instrumentation:mongo:mongo-common:testing") include(":instrumentation:netty:netty-3.8:javaagent") include(":instrumentation:netty:netty-4.0:javaagent") include(":instrumentation:netty:netty-4.1:javaagent") +include(":instrumentation:netty:netty-4.1-common:javaagent") include(":instrumentation:netty:netty-4-common:javaagent") include(":instrumentation:netty:netty-common:javaagent") include(":instrumentation:okhttp:okhttp-2.2:javaagent")