Work around lambda instrumentation failure
Ideally we would ignore instrumenting helper classes...
This commit is contained in:
parent
dac1522a3f
commit
6d63815b44
|
@ -8,6 +8,8 @@ package io.opentelemetry.javaagent.instrumentation.netty.common.client;
|
||||||
import io.netty.channel.ChannelDuplexHandler;
|
import io.netty.channel.ChannelDuplexHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
|
@ -75,17 +77,7 @@ public final class NettySslInstrumentationHandler extends ChannelDuplexHandler {
|
||||||
// netty SslHandler starts the handshake after it receives the channelActive() signal; this
|
// netty SslHandler starts the handshake after it receives the channelActive() signal; this
|
||||||
// happens just after the connection is established
|
// happens just after the connection is established
|
||||||
// this makes connect() promise a good place to start the SSL handshake span
|
// this makes connect() promise a good place to start the SSL handshake span
|
||||||
promise.addListener(
|
promise.addListener(new StartListener(ctx));
|
||||||
future -> {
|
|
||||||
// there won't be any SSL handshake if the channel fails to connect
|
|
||||||
if (!future.isSuccess()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
request = NettySslRequest.create(ctx.channel());
|
|
||||||
if (instrumenter.shouldStart(parentContext, request)) {
|
|
||||||
context = instrumenter.start(parentContext, request);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ctx.connect(remoteAddress, localAddress, promise);
|
ctx.connect(remoteAddress, localAddress, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,4 +104,25 @@ public final class NettySslInstrumentationHandler extends ChannelDuplexHandler {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class StartListener implements GenericFutureListener<Future<Void>> {
|
||||||
|
|
||||||
|
private final ChannelHandlerContext ctx;
|
||||||
|
|
||||||
|
private StartListener(ChannelHandlerContext ctx) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void operationComplete(Future<Void> future) {
|
||||||
|
// there won't be any SSL handshake if the channel fails to connect
|
||||||
|
if (!future.isSuccess()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request = NettySslRequest.create(ctx.channel());
|
||||||
|
if (instrumenter.shouldStart(parentContext, request)) {
|
||||||
|
context = instrumenter.start(parentContext, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.netty.resolver.AddressResolver;
|
||||||
import io.netty.resolver.AddressResolverGroup;
|
import io.netty.resolver.AddressResolverGroup;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest;
|
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest;
|
||||||
|
@ -106,7 +107,7 @@ public final class InstrumentedAddressResolverGroup<T extends SocketAddress>
|
||||||
Context context = instrumenter.start(parentContext, request);
|
Context context = instrumenter.start(parentContext, request);
|
||||||
try {
|
try {
|
||||||
Future<U> future = resolveFunc.get();
|
Future<U> future = resolveFunc.get();
|
||||||
return future.addListener(f -> instrumenter.end(context, request, null, f.cause()));
|
return future.addListener(new OnEndListener<>(request, context));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
instrumenter.end(context, request, null, t);
|
instrumenter.end(context, request, null, t);
|
||||||
throw t;
|
throw t;
|
||||||
|
@ -117,5 +118,22 @@ public final class InstrumentedAddressResolverGroup<T extends SocketAddress>
|
||||||
public void close() {
|
public void close() {
|
||||||
delegate.close();
|
delegate.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// currently cannot use lambda for this
|
||||||
|
private class OnEndListener<U> implements GenericFutureListener<Future<U>> {
|
||||||
|
|
||||||
|
private final NettyConnectionRequest request;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
private OnEndListener(NettyConnectionRequest request, Context context) {
|
||||||
|
this.request = request;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void operationComplete(Future<U> future) {
|
||||||
|
instrumenter.end(context, request, null, future.cause());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue