From b5b51934df9a3d95d82403026a8ad7fe1107b781 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Fri, 2 Jun 2023 23:38:17 +0300 Subject: [PATCH] Fix flaky reactor netty connect span tests (#8636) --- .../TransportConnectorInstrumentation.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java index 312bd9f23d..690724a794 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/TransportConnectorInstrumentation.java @@ -80,6 +80,7 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { @Advice.OnMethodEnter(suppress = Throwable.class) public static void onEnter( @Advice.Argument(0) SocketAddress remoteAddress, + @Advice.Argument(2) ChannelPromise channelPromise, @Advice.Local("otelContext") Context context, @Advice.Local("otelRequest") NettyConnectionRequest request, @Advice.Local("otelScope") Scope scope) { @@ -92,12 +93,15 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { context = connectionInstrumenter().start(parentContext, request); scope = context.makeCurrent(); + + // the span is finished in the mono decorated by the ConnectionWrapper + VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class) + .set(channelPromise, ConnectionRequestAndContext.create(request, context)); } @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) { @@ -109,10 +113,6 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { 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)); } } } @@ -123,6 +123,7 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { @Advice.OnMethodEnter(suppress = Throwable.class) public static void onEnter( @Advice.Argument(0) List remoteAddresses, + @Advice.Argument(2) ChannelPromise channelPromise, @Advice.Argument(3) int index, @Advice.Local("otelContext") Context context, @Advice.Local("otelRequest") NettyConnectionRequest request, @@ -136,12 +137,15 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { context = connectionInstrumenter().start(parentContext, request); scope = context.makeCurrent(); + + // the span is finished in the mono decorated by the ConnectionWrapper + VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class) + .set(channelPromise, ConnectionRequestAndContext.create(request, context)); } @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) { @@ -153,10 +157,6 @@ public class TransportConnectorInstrumentation implements TypeInstrumentation { 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)); } } }